我有一个这样的表:
<table>
<tr class="a"><td></td></tr>
<tr class="b"><td></td></tr>
</table>
有将近800行,大部分都是a类。现在我想像这样切换这些行:
$("#toggle_a").click(function(){
$("tr.a").toggle();
});
$("#toggle_b").click(function(){
$("tr.b").toggle();
});
但这确实非常慢,而且大多数时候浏览器想要停止操作。
有没有人知道如何让这个东西更快更可用?
最佳答案
似乎是因为 jquery 按类名搜索元素..
Note: The class selector is among the slowest selectors in jQuery; in IE it loops through the entire DOM. Avoid using it whenever possible.
同时检查 this文章
关于jQuery.toggle() 在许多 <TR> 元素上非常慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4488880/