我有一个递归 jQuery 函数,其内容如下:
parentItem.find('> div:first-child > span.c-checkbox > input[type="checkbox"]');
它在 Chrome、Firefox、Safari 甚至 IE9 中运行良好。对于 IE8 及更低版本,速度非常慢(15 秒以上)。
我在一篇文章中发现IE8的“查找”表现不佳:http://ethermuse.blogspot.com/2011/07/jquery-find-slow-in-ie8.html 。我不太明白这个概念。有人可以推荐一种方法使其在 IE8 中正常工作吗?
编辑: 我尝试在我的应用程序中用此替换代码片段,我认为我注意到了一个改进:
parentItem.children("div:first-child").children("span.c-checkbox").children("input[type=checkbox]")
选择器是否相同?有什么方法可以衡量这一点?
最佳答案
尝试减少 find() 中高级选择器的数量。
试试这个:
parentItem.find('input:checkbox');
关于javascript - 在IE8中替换 "find"进行优化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9475321/