什么是最快的选择器

pyc*_*cki 1 jquery

只是想改善我的选择器.我有很多行,但我需要排除具有"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>
Run Code Online (Sandbox Code Playgroud)

我知道的很快:

$(".table_row")
Run Code Online (Sandbox Code Playgroud)

这个慢得多:

$(".table_row:not(.valuetemplate")
Run Code Online (Sandbox Code Playgroud)

这是排除的唯一方法吗?

Mik*_*keM 5

$(".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)")

  • 25386
  • ±1.89%
  • 最快的

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

  • 17894
  • ±0.36%
  • 慢了30%