Sizzle中的makeArray函数(jQuery 1.3) [英] makeArray function in Sizzle (jQuery 1.3)

查看:103
本文介绍了Sizzle中的makeArray函数(jQuery 1.3)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用jQuery 1.3时遇到了很多问题。 2 只在我的一个网站上。这是一个Joomla网站,因此Mootools也包含在页面中(并且删除Mootools太难了)。基本上问题是用一个选择器调用基本的jQuery选择器(例如:a,。myClass html a,。myClass td),只返回第一个元素。

I've been having a lot of problems with jQuery 1.3.2 on only one of my sites. It's a Joomla site, so Mootools is included on the page as well (and it's too difficult to remove Mootools). Basically the problem is that calling the basic jQuery selector with one selector (eg: "a", ".myClass", not "html a", ".myClass td"), will only return the first element.

我已经完成了代码并在Sizzle引擎中将其缩小到此功能:

(参见自己,第2058行 jquery.js

I've stepped through the code and have narrowed it down to this function in the Sizzle engine:
(see for yourself, line 2058 jquery.js)

var makeArray = function(array, results) {
    array = Array.prototype.slice.call( array );
    if ( results ) {
        results.push.apply( results, array );
        return results;
    }
    return array;
};

我会在这里再写一遍评论,以显示我在调用后记录的值 jQuery(a)

I'll write it out here again with comments to show the values I've been logging after calling jQuery("a"):

var makeArray = function(array, results) {
    // "array" is an array of all the 58 links on the page
    // "results" is an empty jQuery object

    array = Array.prototype.slice.call( array );

    // array is unchanged.

    if ( results ) {   // true
        results.push.apply( results, array );
        // "results" is now an array only holding the FIRST element.
        return results;
    }
    return array;
};

有人可以向我解释这段代码吗?还有为什么它除了我的一个元素之外的所有元素?

Can someone explain this code to me? And also why it's getting rid of all but one of my elements??

推荐答案

Aaargh,我终于找到了它。我使用的旧版验证插件与之不兼容jQuery 1.3+ - 它已经定义了自己的 push 方法,该方法只将第一个元素推送到数组中,并且调用它而不是常规的jQuery方法。

Aaargh, I finally found it. I was using an older version of the Validation plugin which wasn't compatible with jQuery 1.3+ - it had defined its own push method which only pushed the first element into the array, and this was being called instead of the regular jQuery method.

所以,这是对所有升级后遇到奇怪内容的人的警告:检查插件的兼容性!!

So let this be a warning to all ye who experience weird stuff after upgrading: check the compatibility of your plugins!!

这篇关于Sizzle中的makeArray函数(jQuery 1.3)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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