jQuery类选择器性能(混淆) [英] jQuery class selector performance (confused)

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

问题描述

$('table.selectable td.capable input:text')$('table.selectable td input:text')更可取吗?换句话说,指定类是否会加快或减慢选择的速度(假设在这种情况下不是绝对必需的)?

So is $('table.selectable td.capable input:text') preferable to $('table.selectable td input:text')? In other words, does specifying a class speed up or slow down the selection (assuming it isn't absolutely required in this scenario)?

推荐答案

我没有检查Sizzle实现,但是在最佳情况下,td会映射到类似

I did not check the Sizzle implementation, but in the best case, td would map to something like getElementsByTagName() and .capable to something like getElementsByClassName(), if available. So both would be comparable in terms of speed.

但是,据我所知,还没有getElementsByTagNameAndClassName()方法,因此解决td.capable可能需要在DOM调用之后再进行一次过滤.因此,我很倾向于认为它会更慢.

However, there is no getElementsByTagNameAndClassName() method as far as I know, so resolving td.capable probably requires an additional filtering pass after the DOM call. So, I'm quite inclined to think it would be slower.

自然,基准测试可以肯定地说明这一点.

Naturally, a benchmark would tell for sure.

这篇关于jQuery类选择器性能(混淆)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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