繁体   English   中英

jQuery UI Sortable,如何在旧位置获取DOM元素?

[英]jQuery UI Sortable, how to get DOM element at old position?

我有一个列表,使我可以使用jQuery UI进行排序。 我需要做的是访问现在位于拖动元素原始位置的jQuery对象(DOM元素)。 我将如何去做呢?

我有拖动元素的起始索引是否有帮助?

您可以尝试使用索引:

$(function(){
var startIndex = false;
$('ul').sortable({
    items: ' > li',
    start: function(event,ui){
         startIndex = ui.item.index();
    },
    stop: function(event,ui){
        if(false !== startIndex) {
            $('#result').html('<br />Element on the original place of the moved element: ' + $('li:eq('+startIndex+')').text() + ' ');
        }
        startIndex = false;
    }
});

});

这是小提琴: http : //jsfiddle.net/m3cSu/

暂无
暂无

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

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