我在我的一个网站上遇到过很多关于jQuery 1.3.2的问题.这是一个Joomla网站,所以Mootools也包含在页面中(并且删除Mootools太难了).基本上问题是用一个选择器调用基本jQuery选择器(例如:"a", ".myClass",not "html a", ".myClass td"),只会返回第一个元素.
我已经逐步完成了代码并将其缩小到Sizzle引擎中的这个函数:(
请参阅自己,第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;
};
Run Code Online (Sandbox Code Playgroud)
我将在这里再次写下评论,以显示我在调用后记录的值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;
};
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释这段代码吗?还有为什么它除了我的一个元素之外什么都没有?
Aaargh,我终于找到了它.我使用的是旧版本的Validation插件,它与jQuery 1.3+不兼容 - 它已经定义了自己的push方法,只将第一个元素推送到数组中,并且这被调用而不是常规的jQuery方法.
因此,对于升级后遇到奇怪内容的所有人,请注意这一点:检查插件的兼容性!
| 归档时间: |
|
| 查看次数: |
1060 次 |
| 最近记录: |