jquery-ui – jQuery UI Sortable,如何确定更新事件中的当前位置和新位置?

我有
<ul id="sortableList">
     <li>item 1</li>
     <li>item 2</li>
     <li>item 3</li>
</ul>

我有线到更新:function(event,ui){}但不知道如何获得元素的原始和新的位置。如果我将项目3移动到项目1之上,我想要原始位置为2(基于0的索引),项目3的新位置为0。

解决方法

$('#sortable').sortable({
    start: function(e,ui) {
        // creates a temporary attribute on the element with the old index
        $(this).attr('data-previndex',ui.item.index());
    },update: function(e,ui) {
        // gets the new and old index then removes the temporary attribute
        var newIndex = ui.item.index();
        var oldindex = $(this).attr('data-previndex');
        $(this).removeAttr('data-previndex');
    }
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...