2
我遇到了將jQueryUI droppable應用到動態創建的div的問題。jQuery UI可以動態添加元素嗎?
$(".item").draggable({ helper: 'clone'});
$(".box").draggable({containment : '#area'});
$(".box").droppable({
drop: function(event, ui) {
if ($(ui.draggable).hasClass("area")){
// call another function
}else{
$(this).append($(ui.draggable).clone().removeClass('item').addClass('area'));
$('.area').draggable();
}
}
});
的.item
應該在.box
下降。它工作得很好,直到我所說的第二個功能(通過點擊一個按鈕):
function add_box(){
$("<div class='box'></div>").prependTo("#area");
$(".box").droppable(); // i tried this (didn't work).
$(".box").draggable(); // should be draggable as well
}
我試過你的解決方案,但droppable/draggable不會應用到newBox。還有什麼我可以做的嗎?無論如何感謝 –
我得到它使用$(newBox).droppable()。 –