好的方法来提高jQuery选择器的性能? [英] Good ways to improve jQuery selector performance?

查看:154
本文介绍了好的方法来提高jQuery选择器的性能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找任何方法,我可以提高选择器的性能的jQuery调用。具体来说:

I'm looking for any way that I can improve the selector performance of a jQuery call. Specifically things like this:

$(div.myclass) $(。myclass)

我认为它可能是,但我不知道jQuery是否足够聪明,

I would think it might be, but I don't know if jQuery is smart enough to limit the search by tag name first, etc. Anyone have any ideas for how to formulate a jQuery selector string for best performance?

推荐答案

有没有任何想法如何制定一个jQuery选择器字符串以获得最佳性能?

There is no doubt that filtering by tag name first is much faster than filtering by classname.

这是在所有浏览器都实现getElementsByClassName之前的情况。 ,如getElementsByTagName的情况。

This will be the case until all browsers implement getElementsByClassName natively, as is the case with getElementsByTagName.

这篇关于好的方法来提高jQuery选择器的性能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆