我在将 jQueryUI droppable 应用于动态创建的 div 时遇到问题。
$(".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();
}
}
});
Run Code Online (Sandbox Code Playgroud)
An.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
}
Run Code Online (Sandbox Code Playgroud)