如何获得可拖动的内部掉落事件的容器?

时间:2008-11-18 22:03:50

标签: javascript jquery dom

我有一个像这样的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对象的容器。我怎么能这样做?

2 个答案:

答案 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);
    }
});