gpt4 book ai didi

jquery - 最快的选择器是什么

转载 作者:行者123 更新时间:2023-12-01 06:57:51 25 4
gpt4 key购买 nike

只是想改进我的选择器。我有很多行,但我需要排除具有“table_row valuetemplate”类的行。

<table>      
<tr class="table_row"></tr>
<tr class="table_row"></tr>
<tr class="table_row"></tr>
<tr class="table_row valuetemplate"></tr>
</table>

我很快就知道了:

$(".table_row")

这个要慢得多:

$(".table_row:not(.valuetemplate")

这是唯一的排除方法吗?

最佳答案

$(".table_row:not(.valuetemplate)") 似乎是最快的(在 Chrome 13 和 FF 5 中测试,结果来自 Chrome)

http://jsperf.com/not-jquery-selectors

$(".table_row").not('.valuetemplate')

  • 17,977 次操作/秒
  • ±0.13%
  • 慢 29%

$(".table_row:not(.valuetemplate)")

  • 25,386
  • ±1.89%
  • 最快

$("table").children(":not(.valuetemplate)");

  • 17,894
  • ±0.36%
  • 慢 30%

关于jquery - 最快的选择器是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7086379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com