问题描述
这个通过我来循环,但我最终追溯到回调中的事件对象参数的变化。让我概述一下这个问题:
Ok this one through me for a loop, but I finally traced it down to changes in the event object parameter on callbacks. Let me outline the problem:
我最近从1.6.2升级到jquery 1.7并发现一些奇怪的事情发生。
I recently upgraded to jquery 1.7 from 1.6.2 and noticed some strange things happen.
最引人注目的是我的jquery-ui(1.8.16)sortables开始出现一些不必要的副作用:
Most noticeably my jquery-ui (1.8.16) "sortables" began to have some unwanted side-effects:
HTML STRUCTURE
HTML STRUCTURE
<ul id="ulFeatured">
<li><span class="Title">Item 1</span></li>
<li><span class="Title">Item 2</span></li>
<li><span class="Title">Item 3</span></li>
</ul>
<ul id="ulAvailable">
<li><span class="Title">Item 4</span></li>
<li><span class="Title">Item 5</span></li>
<li><span class="Title">Item 6</span></li>
</ul>
JQUERY
$("#ulFeatured, #ulAvailable").sortable
(
{
connectWith: ".connectedSortable",
receive: function (event, ui)
{
console.log(event.target);
}
}
).disableSelection();
结果
1.6.12
<ul id="ulFeatured" class="connectedSortable ui-sortable NoItems" style="">
1.7
<span class="Title">
任何人对此有任何见解?我想使用event.target的原始功能作为接收项目的项目。
Anyone have any insights into this one? I would like to use the original functionality of the event.target being the item receiving the item.
谢谢! :)
推荐答案
你可以使用jQuery方法 .closest()
找到该项目所属的列表。
You could use the jQuery method .closest()
to find the list that the item belonged to.
$("#ulFeatured, #ulAvailable").sortable
(
{
connectWith: ".connectedSortable",
receive: function (event, ui)
{
console.log($(event.target).closest('ul'));
}
}
).disableSelection();
这篇关于升级到jQuery 1.7并更改事件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!