拖放jquery

时间:2010-09-04 06:06:17

标签: jquery

我没有得到掉掉另一个div的div的id 我得到id_droppable我但没有得到id_dropped div 警报id_dropped给出未定义的结果

请帮我验证我的代码并更正错误。

$(".full-circle").droppable({
    accept: ".unseated_guest",
    drop: function(event, ui) {
        var id_droppable = this.id;
        alert(id_droppable);
        var id_dropped = ui.id;
        alert(id_dropped);
        var name=document.getElementById("div_name_0").value;
        $(this).css("background-color","red");
        $(this).append(ui.draggable);
        //$(this).draggable('disable');
        }

    });

2 个答案:

答案 0 :(得分:0)

ui参数没有id属性,因为它是对药物元素的引用。您需要获得id ui.draggable.attr('id'),或者您喜欢的任何方法来获取元素的id

$(".full-circle").droppable({
    accept: ".unseated_guest",
    drop: function(event, ui) {
        //Stuff above
        var id_dropped = ui.draggable.attr('id');
        alert(id_dropped);
        //Stuff below
        }

    });

答案 1 :(得分:0)

在放置处理程序中,$(this)是可放置的,ui.draggable是可拖动的(作为jQuery对象)。所以对于droppable:

$(this).attr('id');
// or
this.id;

对于可拖动的人来说:

ui.draggable.attr('id');
// or, for the sake of symmetry:
ui.draggable[0].id;
相关问题