如何获得可拖动元素的“索引”?

时间:2013-08-10 17:22:21

标签: jquery jquery-ui

对于可排序元素,我会使用ui.item.index()。是否存在可拖动元素的等价物?

$('.elem').draggable({
  start: function(event, ui){
    //How do I get the "index" of ui.item?
  }
});

1 个答案:

答案 0 :(得分:1)

只需像使用其他任何地方一样使用jquery.index()

$('.elem').draggable({
    start: function () {
        var myIndex = $(this).index();
        $(this).text('I am #' + myIndex);    
    }
});

这里是fiddle

相关问题