我有:
<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'); } });
原文地址:https://www.jb51.cc/jquery/185108.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。