jQuery中最接近IE的行为非常慢 [英] jQuery closest behaviour in IE very slow
问题描述
我有一个5000行的表。在每一行中我都有一个html元素。 myElementList是这些元素的列表。现在我需要选择这些元素的所有tr。我使用以下代码。
I have a table with 5000 rows. In each row I have an html element. myElementList is the list of those elements. Now I need to select all the tr's of these elements. I am using the following code.
myElementList.closest('tr');
这项工作非常适合FF。但是当我在IE 8中运行相同时。浏览器停止运行并出现一个弹出式杂乱的东西,用于停止脚本。
This work great in FF. But when I run the same in IE 8. The browser hangs out and a popup messgae appears that propmt for to stop the script.
任何建议为什么我看到这种行为或其他任何选择。
Any suggestion why I am seeing this behaviour or thier is any alternative.
编辑:
当行为保持不变时我使用parents()
The behaviour remains same when I use parents()
myElementList.parents('tr');
推荐答案
得到你想要的东西相当活泼(最亲密的父母) tr到每个选中的复选框)你可以这样做:
To get what you wish fairly snappy (the closest parent tr to every checked checkbox) you'd could do something like this:
$.fn.extend({
closestByTagName: function(tagname) {
var tag = tagname.toUpperCase(), i = this.length, node, found=[], trParents;
while(i--) {
node = this[i];
while((node=node.parentNode) && node.nodeName != tag);
if(node) {
found[found.length] = node;
}
}
return $(found);
}
});
var result = $('input:checked').closestByTagName('tr');
它不漂亮,但我想不出更快的方式。 (它应该大幅击败jQuery)
It isn't pretty, but i can't think of a faster way. (it should beat jQuery by a wide margin)
这篇关于jQuery中最接近IE的行为非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!