Jquery droppable 获取可拖动的 id
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10665901/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Jquery droppable get draggable id
提问by Akshay
I want to get dragged id when i dropped to the certain div
当我下降到某个 div 时,我想被拖动 id
Drag <ul id="demo" >
<li id="1" ></li>
<li id="2" ></li>
<li id="3" ></li>
</ul>
<div class="drop"> drop here!! </div>
JQUERY
查询
$(".drop").droppable({
drop: function(event, ui) {
// i need to get dragged id (note:able to drag multiple ids)
1,2,3..
}
});
Please help me out!! Thnks
请帮帮我!!谢谢
回答by Prasenjit Kumar Nag
As they says in jQuery UI dropabledoc
正如他们在 jQuery UI dropabledoc 中所说
All callbacks receive two arguments: The original browser event and a prepared ui object, view below for a documentation of this object (if you name your second argument 'ui'):
ui.draggable - current draggable element, a jQuery object.
ui.helper - current draggable helper, a jQuery object
ui.position - current position of the draggable helper { top: , left: }
ui.offset - current absolute position of the draggable helper { top: , left: }
所有回调都接收两个参数:原始浏览器事件和准备好的 ui 对象,查看下面的此对象的文档(如果您将第二个参数命名为“ui”):
ui.draggable - 当前可拖动元素,一个 jQuery 对象。
ui.helper - 当前可拖动助手,一个 jQuery 对象
ui.position - 可拖动助手的当前位置 { top: , left: }
ui.offset - 可拖动助手的当前绝对位置 { top: , left: }
ui.draggable
is the element being dropped as a jQuery object
.
ui.draggable
是作为jQuery object
.
So You can get the ID using ui.draggable.prop('id')
所以你可以使用 ui.draggable.prop('id')
回答by VisioN
You can use ui.draggable
to address draggable element.
您可以使用ui.draggable
来解决可拖动元素。
drop: function(event, ui) {
var id = ui.draggable.attr("id");
}
回答by Suresh
you can append the dropped nodes to a div, through the div you can get all the dropped ids. like below
您可以将删除的节点附加到 div,通过 div 您可以获得所有删除的 id。像下面
$(".drop").droppable({
drop: function(event, ui) {
var id= ui.draggable.attr("id");
$("#dropped-divs").append(id);
}