如何获取可排序元素的ID? [英] How do I get the id of sortable element?
本文介绍了如何获取可排序元素的ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Sortable并将其启动并工作.但是我正在尝试保存列表中的内容.
I'm using Sortable and got it up and working. But I'm trying to save what is where inside the lists.
假设我有3个列表:
<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();
我试图在sortable中使用stop
事件,但是它当然只返回ul
的ID.因此,我要的是jQuery告诉我何时将elem1
从list1
移到list2
(当然也可以是任何elemX
).
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.
推荐答案
I think you want to use the receive
callback:
$("#top, #left, #right").sortable({
connectWith: ".connectedSortable",
receive: function(event, ui) {
alert("[" + this.id + "] received [" + ui.item.html() + "] from [" + ui.sender.attr("id") + "]");
}
}).disableSelection();
这篇关于如何获取可排序元素的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文