[英]how to figure out which list item has been dropped
我有3栏。
<div id="catalog">
<ul id="author">
<li>Different Author names</li>
....
</ul>
<ul id="genre">
<li>Different Genres</li>
</ul>
<ul id="publish">
<li>Different Publishers<li>
</ul>
</div>
我使用jQuery将这些列表中的项目拖放到这样的其他列表购物车中
$(function() {
$( "#catalog li" ).draggable({
appendTo: "body",
helper: function( event ) {
return $( "<li class='bit-box'>" + $(this).text() + "</li>" );
},
cursorAt: { cursor: "move", top: 5, left: 5 }
});
$( "#cart ul" ).droppable({
accept: ":not(.ui-sortable-helper)",
drop: function( event, ui ) {
$( this ).find( ".placeholder" ).remove();
$( this ).find( "li:contains('" + ui.draggable.text() + "')" ).remove();
$( "<li class='bit-box'></li>" ).text(ui.draggable.text()).append("<a class='closebutton' href='#' onclick='$(this).parent().remove();'></a>").appendTo( this );
}
});
有什么办法可以确定被删除的项目属于哪个列表。
感谢您的帮助。
尝试在drop
处理程序中使用此命令:
ui.draggable.closest('ul').attr('id')
它应该为您提供放置项目所属列表的ID。
您应该检查$(this).parent()。id属性。 如果您想要父级列表的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.