父元素id
无法获取项目拖入的列表的父 ID。我可以很容易地获得物品的 ID,并认为我可以从中获得父项,但似乎无法抓住它!
<li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li>
是李被拖进来的。非常感谢任何帮助!
$("li.tag").draggable({
connectToSortable: 'ul.assignedClass',
helper: 'clone',
stop: function(event, ui) {
projectTags('add',$(this))
}
});
function projectTags(fnc, tag){
var tagID = $(tag).attr("id")
var parentID = $("#"+tagID).closest('ul').attr("id"); /// closest, parent & parents doesn't work?
$("#fdbk").prepend("<li>fnc:"+fnc+", tag:"+tagID+" < "+ $("#"+tagID).parents("ul:first").attr("id")+"</li>");
}
html;
<ul id="tags_978" class="assignedClass ui-sortable">
<li id="existingTag_1029" class="tagAssigned">space </li>
<li id="existingTag_1030" class="tagAssigned">light </li>
<li id="existingTag_1031" class="tagAssigned">continuous landscape </li>
<li id="existingTag_1032" class="tagAssigned">structural glass </li>
<li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li>
</ul>
can't get the parent id of the list the item is dragged into. I can get the items' id easily enough and thought i could get the parent from that but can't seem to grab it!
<li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li>
is the li dragged in. Any help much appreciated!
$("li.tag").draggable({
connectToSortable: 'ul.assignedClass',
helper: 'clone',
stop: function(event, ui) {
projectTags('add',$(this))
}
});
function projectTags(fnc, tag){
var tagID = $(tag).attr("id")
var parentID = $("#"+tagID).closest('ul').attr("id"); /// closest, parent & parents doesn't work?
$("#fdbk").prepend("<li>fnc:"+fnc+", tag:"+tagID+" < "+ $("#"+tagID).parents("ul:first").attr("id")+"</li>");
}
html;
<ul id="tags_978" class="assignedClass ui-sortable">
<li id="existingTag_1029" class="tagAssigned">space </li>
<li id="existingTag_1030" class="tagAssigned">light </li>
<li id="existingTag_1031" class="tagAssigned">continuous landscape </li>
<li id="existingTag_1032" class="tagAssigned">structural glass </li>
<li id="tag_772" class="tag tagAssigned ui-draggable" >adventurous briefs</li>
</ul>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
编辑:
试试这个;)
EDIT:
try this;)
将 the 更改
为
这可以避免嵌套 dom 解析,并在语句末尾添加分号。
编辑:为了清楚起见,另外:
change the
to
This avoids the nested dom parse, and adds the semicolon on the end of the statement.
EDIT:for clarity and in addition:
好吧——走了很长一段路...
ok - gone the long way round...