简体   繁体   English

jQuery-获取可排序列表的索引

[英]jQuery - Getting index of sortable list

Let's say I have a sortable list like this: 假设我有一个像这样的可排序列表:

$(".song-list").sortable({
  handle : '.pos_handle',
  axis : 'y',
  opacity: 0.6,
  update : function () {
    var id = $(this).index();
    console.log("Moved to new position: " + id);
  }
});

When you move the list, it should update in console with the new position. 移动列表时,它应在控制台中以新位置更新。 The .pos_handle has no ID.. only the class. .pos_handle没有ID ..只有类。

How would I get the index of it's new moved-to position? 我如何获得新的头寸指数?

Use the prepared ui object's .item property to reference the current element being moved: 使用准备好的ui对象的.item属性引用当前要移动的元素:

update : function (event, ui) {
    console.log("Moved to new position: " + ui.item.index());
}

Fiddle 小提琴

jQuery UI Reference jQuery UI参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM