Get the item/object where the element is dropped

99封情书 提交于 2019-12-22 04:58:11

问题


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:

$( ".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!!!


回答1:


Very Simple:

alert($(this).attr('id')); //this is element where the item was dropped in 



回答2:


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/



来源:https://stackoverflow.com/questions/9584816/get-the-item-object-where-the-element-is-dropped

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!