javascript 获取元素被放置的项目/对象
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9584816/
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
Get the item/object where the element is dropped
提问by javimaravillas
I'm coding a task panel with three lists and I use sortable to move item between them. But I need to pick up the item where the element is dropped. I know that ui.item
is the element dropped, but I don't know where I dropped it. Here is my code:
我正在编写一个包含三个列表的任务面板,我使用 sortable 在它们之间移动项目。但我需要拿起元素被丢弃的项目。我知道那ui.item
是元素掉了,但我不知道我把它放在哪里了。这是我的代码:
$( ".column" ).sortable({
receive: function(event, ui) {
/* get the element where ui.item is dropped */
}
});
I know that the element will be any with the .column
selector, but how to pick!!!
我知道元素将是任何带有.column
选择器的元素,但是如何选择!!!
采纳答案by Alex Shuraits
Very Simple:
很简单的:
alert($(this).attr('id')); //this is element where the item was dropped in
回答by Nicola Peluchetti
EDIT - a way to do that is like this
编辑 - 一种方法是这样的
$("#sortable1, #sortable2").sortable({
connectWith: ".connectedSortable",
receive: function(e, ui) {
alert(ui.item.closest('ul').attr('id'));
}
}).disableSelection();
Of course if you wan't to get the element next to the dropped element you'd do
当然,如果您不想在已删除的元素旁边获取元素,您可以这样做
ui.item.closest('ul')
fiddle here http://jsfiddle.net/dKaYM/