0
我有一個列表,我已經使用jQuery UI進行排序。我需要做的是訪問現在處於拖動元素原始位置的jQuery對象(DOM元素)。我會如何去做這件事?jQuery UI可排序,如何在舊位置獲取DOM元素?
如果有幫助,我有拖動元素的起始索引?
我有一個列表,我已經使用jQuery UI進行排序。我需要做的是訪問現在處於拖動元素原始位置的jQuery對象(DOM元素)。我會如何去做這件事?jQuery UI可排序,如何在舊位置獲取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/