比较jQuery选择器的性能 [英] compare jquery selectors performance
问题描述
希望提高我的jquery选择器的性能.因此,任何技巧或文章都是最佳的共振峰jquery选择器?例如,选择div的ID.我可以在任何地方在线提供html并比较可以用来选择所需元素的不同选择器.
Looking at improving the performance of my jquery selectors. so any tips or articles as the best per formant jquery selectors? For example selecting the a div's id. Anywhere online I can provide html and compare the different selectors I can use to select the required element.
推荐答案
您可以在此处比较选择器的性能: http://jsperf. com/
You can compare selector performance here: http://jsperf.com/
只需设置HTML,包括jQuery,然后将要比较的每个选择器作为测试用例即可.
Just setup your HTML, include jQuery and place each selector you want to compare as a test case.
许多规则此处仍然适用,但是游戏在jQuery 1.4.3+中有所变化,此后Sizzle(jQuery的选择器引擎)将使用 querySelectorAll()
在支持它的浏览器中.
Many of the rules here still apply, however the game changed a bit in jQuery 1.4.3+, after that Sizzle (jQuery's selector engine) will use querySelectorAll()
in browsers that support it.
这篇关于比较jQuery选择器的性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!