【发布时间】:2012-11-23 09:16:18
【问题描述】:
我试图理解为什么this jsperf test 中的一个 sn-ps 似乎比其他的慢得多。
这是四个sn-ps:
$(".menu-vertical li.selected > ul.static").show().parents().show();
$('ul.root').find('li.selected').children('ul.static').show().parents().show();
$("ul.root li.selected > ul.static").show().parents().show();
$('ul.root li.selected').children('ul.static').show().parents().show();
第二个似乎在所有浏览器中始终较慢,我不明白为什么。
【问题讨论】:
-
我给出了两个性能示例 1) find() vs Direct Child(>) 选择器 vs 子选择器性能测试 1 [jsperf.com/jquery-child-selector-vs-find/2][link1] 2) find() vs 后代选择器 vs 子选择器性能测试2 [jsperf.com/jquery-child-selector-vs-find/9][link2] [链接1]:jsperf.com/jquery-child-selector-vs-find/2 [链接2]:jsperf.com/jquery-child-selector-vs-find/9
标签: jquery performance jquery-selectors