我试图从丢弃的元素中获取id,但没有任何运气(或技能)。使用droppable而不是sortable,您可以使用ui.draggable
访问该元素。
<body>
<ul id="sortable1" class="connectedSortable">
<li class="ui-state-default">Item 1</li>
<li class="ui-state-default">Item 2</li>
<li class="ui-state-default">Item 3</li>
<li class="ui-state-default">Item 4</li>
<li class="ui-state-default">Item 5</li>
</ul>
<ul id="sortable2" class="connectedSortable">
<li id="balls" class="ui-state-highlight">balls</li>
<li class="ui-state-highlight">Item 2</li>
<li class="ui-state-highlight">Item 3</li>
<li class="ui-state-highlight">Item 4</li>
<li class="ui-state-highlight">Item 5</li>
</ul>
</body>
$(function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable",
receive: function( event, ui ) { alert($(this).attr('id') +' - '+ ui.draggable); },
stop: function( event, ui ) { alert($(this).ui.draggable.attr('id')); }
}).disableSelection();
});
答案 0 :(得分:0)
使用ui.item
(请参阅http://api.jqueryui.com/sortable/#event-receive):
$(function() {
$( "#sortable1, #sortable2" ).sortable({
connectWith: ".connectedSortable",
receive: function( event, ui ) { alert($(this).attr('id') +' - '+ ui.item); },
stop: function( event, ui ) { alert($(ui.item).attr('id')); }
}).disableSelection();
});