【问题标题】:Why can't I get Draggable ID when Dropped in a Droppable?为什么我在 Droppable 中放置时无法获得 Draggable ID?
【发布时间】:2014-08-01 22:10:23
【问题描述】:

我在让 ui.draggable 工作时遇到问题。我希望能够返回它的 ID。它返回的都是未定义的,我不明白。

这是我的可挂断电话....

$( ".currqcontainer" ).droppable({ 
    accept: ".currqwrapper",
    drop: function (ui, event) {
        alert("dropped");
        var testid = $(ui.draggable).attr('id');
        alert(testid);
    }   
});

这是我的可拖动初始化...

$( ".currqwrapper" ).draggable({ revert: "invalid" });

我正在使用此脚本创建 currqwrapper 实例。

var $div = $("<div/>", {id: objectID, class: "currqwrapper", text: question});          
$("#currQ" + (i+1)).append($div);

如果有人能告诉我为什么我无法正确读取 ID,那就太好了。显然,我也可以提供您需要的任何其他东西!

这是我的 CONSOLE.LOG(UI)它有我需要的 ID #ZiuFEYAcpP 但我不知道如何调用它?我注意到它在 toElement...

toElement: div#ZiuFEYAcpP.currqwrapper.ui-draggable.ui-draggable-handle
accessKey: ""
align: ""
attributes: NamedNodeMap
0: id
baseURI: null
childNodes: NodeList[1]
firstChild: text
baseURI: null
childNodes: NodeList[0]
data: "ZiuFEYAcpP"
firstChild: null
lastChild: null
length: 10
localName: null
namespaceURI: null
nextElementSibling: null
nextSibling: null
nodeName: "#text"
nodeType: 3
nodeValue: "ZiuFEYAcpP"

【问题讨论】:

    标签: javascript jquery jquery-ui draggable droppable


    【解决方案1】:

    您已颠倒了 drop 事件的参数。 而不是

    drop: function (ui, event) {...
    

    drop: function (event, ui) {
    

    【讨论】:

    • 天哪。我花了几个小时在上面。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多