升级到jQuery 1.7并更改事件对象 [英] Upgrading to jQuery 1.7 and changes to the event object

查看:57
本文介绍了升级到jQuery 1.7并更改事件对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个通过我来循环,但我最终追溯到回调中的事件对象参数的变化。让我概述一下这个问题:

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并更改事件对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆