How do I get the id of sortable element?

╄→尐↘猪︶ㄣ 提交于 2019-12-12 08:05:01

问题


I'm using Sortable and got it up and working. But I'm trying to save what is where inside the lists.

Lets say i have 3 lists:

<ul id="top" class="connectedSortable">
<li>elem1</li>
<li>elem2</li>
<li>elem2</li>
</ul>

<ul id="left" class="connectedSortable">
</ul>

<ul id="right" class="connectedSortable">
</ul>

jQuery:

$("#top, #left, #right")
.sortable({
    connectWith: ".connectedSortable",
    stop: function(event, ui)
    {
        alert(this.id); // printing top, left right...
    }
})
.disableSelection();

I've tried to use the stop event inside sortable but it only returns the ul's id of course. So what I want is jQuery to tell me when I've moved elem1 from list1 to list2 (or any elemX of course).

I'm trying to make a homepage that the user could define the layout themselves.


回答1:


I think you want to use the receive callback:

http://jsfiddle.net/nzskv/1/

$("#top, #left, #right").sortable({
    connectWith: ".connectedSortable",
    receive: function(event, ui) {
        alert("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
    }
}).disableSelection();


来源:https://stackoverflow.com/questions/5244869/how-do-i-get-the-id-of-sortable-element

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