2013-08-06 2 views
0

jQuery UI를 사용하여 정렬 가능하게 만든 목록이 있습니다. 내가 할 수있게하기 위해서는 드래그 된 요소의 원래 위치에있는 jQuery 객체 (DOM 요소)에 액세스해야합니다. 이 일을 어떻게 하죠?jQuery UI Sortable, 이전 위치에서 DOM 요소를 얻는 방법?

드래그 한 요소의 시작 인덱스가 도움이된다면 어떻게됩니까?

답변

0

당신은 인덱스 재생이 시도 할 수 있습니다 :

$(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/