jQuery UI可排序位置 [英] jQuery UI Sortable Position
本文介绍了jQuery UI可排序位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当元素在可排序列表中的位置更改时,如何跟踪元素的位置?
How do I track what position an element is when its position in a sortable list changes?
推荐答案
您可以使用事件提供的ui
对象,特别是希望 .index()
,如下所示:
You can use the ui
object provided to the events, specifically you want the stop
event, the ui.item
property and .index()
, like this:
$("#sortable").sortable({
stop: function(event, ui) {
alert("New position: " + ui.item.index());
}
});
您可以在此处看到有效的演示,请记住.index()
值是从零开始的,所以您可能需要+1以用于显示.
You can see a working demo here, remember the .index()
value is zero-based, so you may want to +1 for display purposes.
这篇关于jQuery UI可排序位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文