[英]jQuery Draggable / Droppable - Remove all dropped 'items'
是否可以通過按一個按鈕刪除可放置div上的所有掉落的“項目”?
謝謝,LS
$("#wrapper").droppable({
accept: '.shape',
drop: function(event, ui)
{
$(this).append($(ui.helper).clone());
$("#wrapper .shape").addClass("item");
$(".item").removeClass("ui-draggable shape");
$(".item").draggable({
containment: '#wrapper'
});
}
});
$("#trash").droppable({
accept: '.item',
drop: function(event, ui)
{
$(ui.draggable).remove();
}
});
我創建了一個名為trash的div,所以當項目被刪除時,它們會被刪除。 我需要類似的功能,但是當按下按鈕時,它會刪除所有掉落的形狀,而不必將它們拖到垃圾div上。
只需使用item
類刪除所有元素:
$('#someButton').click(function() {
$("#wrapper .item").remove();
});
邊注:
您可以這樣做,而不是再次使用$("#wrapper .shape")
選擇丟棄的.shape
元素
ui.helper.clone() // ui.helper is already a jQuery object
.appendTo(this)
.toggleClass("item ui-draggable shape");
.draggable({
containment: '#wrapper'
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.