改进低效的jQuery选择器 [英] improve inefficient jQuery selector
本文介绍了改进低效的jQuery选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在IntelliJ中,如果我使用jQuery选择器,例如:
In IntelliJ, if I use a jQuery selector such as:
$('#roleField option').each(function() {
// impl omitted
});
选择器突出显示我应该
拆分后代选择器,前面带有ID选择器
split descendant selectors which are prefaced with ID selector
IntelliJ建议我究竟是什么应该用?替换上面的选择器?
what exactly is IntelliJ suggesting that I should replace the selector above with?
推荐答案
从jquery文档中,这个方法不会通过Sizzle扇区引擎:
From the jquery documentation this method will not go through the Sizzle sector engine:
$('#roleField option').each(function() {
// No Sizzle
});
这个会是:
$('#roleField').find('option') // Sizzle!
查看ID base selectors部分此处。因此,第二种方法将比第一种方法更快。
Look at the ID base selectors section here. Hence the second method will be faster than the first.
这篇关于改进低效的jQuery选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文