为什么将其拖放到Droppable中却无法获得Draggable ID? [英] Why can't I get Draggable ID when Dropped in a Droppable?
问题描述
我在操作ui.draggable时遇到问题.我希望能够返回其ID.它返回的所有内容都是不确定的,我不明白.
I am having a problem getting ui.draggable to work. I am hoping to be able to return its ID. All it returns is undefined, which I do not understand.
这是我的挂断电话....
Here is my droppable call....
$( ".currqcontainer" ).droppable({
accept: ".currqwrapper",
drop: function (ui, event) {
alert("dropped");
var testid = $(ui.draggable).attr('id');
alert(testid);
}
});
这是我可拖动的初始化...
Here is my draggable initialization...
$( ".currqwrapper" ).draggable({ revert: "invalid" });
我正在使用此脚本创建currqwrapper实例.
I am creating the currqwrapper instances with this script.
var $div = $("<div/>", {id: objectID, class: "currqwrapper", text: question});
$("#currQ" + (i+1)).append($div);
如果你们中的任何一个可以告诉我为什么我无法正确读取该ID,那将非常有用.显然,我也可以提供您需要的其他任何东西!
If any of you could tell me why I am not correctly able to read the ID that would be great. Obviously I can provide anything else you need as well!
这里是我的CONSOLE.LOG(UI)它在#ZiuFEYAcpP中具有我需要的ID,但是我不确定如何调用它吗?我注意到它在toElement中...
HERE IS MY CONSOLE.LOG(UI)It has the ID I need in there #ZiuFEYAcpP but I am not sure how to call it out? I notice it is in the 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"
推荐答案
您已撤销放置事件的参数. 代替
You have reversed the parameters on the drop event. instead of
drop: function (ui, event) {...
写
drop: function (event, ui) {
这篇关于为什么将其拖放到Droppable中却无法获得Draggable ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!