这看起来应该是一个简单的任务,但就 jQuery 而言,我是一个新手,所以这就是我要找的东西:
我有这样的东西:
<div class=draggable id=thing1> some contents </div>
<div class=draggable id=thing2> some other contents </div>
.
.
.
<div class=draggable id=thingN> content </div>
使用这个 Javascript:
$(function() {
$(".draggable").draggable();
// from inside this block, how can I know the id of the thing I'm dragging?
}
最佳答案
使用 stop
回调,并访问 this
的 id
属性(对被删除元素的引用)。
$(".draggable").draggable({
stop: function() { alert(this.id); }
});
jsFiddle .
关于被拖动项目的 jQuery Id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7035727/