我有一个像这样的HTML:
<div id="container1">
<div class="dragme">drag me</div>
</div>
<div id="container2">
<div class="dragme">drag me</div>
</div>
<div id="droponme"></div>
$(".dragme").draggable();
$("#droponme").droppable({
accept: ".dragme",
drop: function(e, u) { alert( /* find id of the container here*/ ); };
});
我想在drop事件处理程序中找到draggable对象的容器。我怎么能这样做?
答案 0 :(得分:2)
$(".dragme").draggable();
$("#droponme").droppable({
accept: ".dragme",
drop: function(e, u) {
alert(u.draggable.parent().attr('id') );
// in your example: container1 or container2
}
});
答案 1 :(得分:0)
这是获得可投放容器的另一种形式:
$(".dragme").draggable();
$("#droponme").droppable({
accept: ".dragme",
drop: function(e, u) {
alert(e.toElement);
}
});