jQuery UI Sortable Position

后端 未结 4 1847
小蘑菇
小蘑菇 2020-12-07 08:03

How do I track what position an element is when its position in a sortable list changes?

4条回答
  •  旧巷少年郎
    2020-12-07 08:31

    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());
        }
    });
    

    You can see a working demo here, remember the .index() value is zero-based, so you may want to +1 for display purposes.

提交回复
热议问题