![](/img/trans.png)
[英]How do i get the index of the draggable ui.helper in a sortable list?
[英]How to get which div/ui.helper clicked in drag event jqueryui/jquery?
在 Jquery UI 的网站上:
http://jqueryui.com/demos/draggable/
如果我有:
<div id="someId" class="someClass">he</div>
<div id="otherId" class="otherClass">he2</div>
和:
$('#someid','#otherid').draggable({
drag: function(event, ui) {
alert(ui.helper.THEIDOFTHECLICKEDITEM); // What goes here?
}
});
如何使用回调中的“ui”变量获取 ID 的 ID 或 class? 如果不可能,我如何从“事件”变量中获取它?
你要:
$("#someId, #otherId").draggable({
drag: function(event, ui) {
console.log(ui.helper[0].id);
}
});
(或使用ui.helper.attr("id")
)
注意: ui.helper
是 jQuery object,这就是为什么我们必须使用.attr("...")
来检索id
或访问索引 0 处的匹配元素并直接获取 id。
或者不使用ui
参数(可能是我推荐的):
$("#someId, #otherId").draggable({
drag: function(event, ui) {
console.log(this.id); // "this" is the DOM element being dragged.
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.