使用“:not”之间的性能差异和“.not()”选择器? [英] Performance differences between using ":not" and ".not()" selectors?

查看:206
本文介绍了使用“:not”之间的性能差异和“.not()”选择器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下两行之间有任何速度/效率差异。

  $(table td:not(:first-child))

  $(table td) .not(:first-child)

我会认为第一个会更好,因为它是删除对象,但有一个实际的差异,是实质性的。



感谢

解决方案

取决于浏览器。

支持 querySelectorAll 的浏览器将提高性能。

  $(table td:not(:first-child))

...因为它是一个有效的选择器。旧的浏览器(IE7及更低版本)不会。



您需要注意:not / code> selector。 jQuery(Sizzle)使用非标准选择器扩展它,因此很容易打破 qSA


Are there any speed/efficiency differences between the following two lines.

$("table td:not(:first-child)")

and

$("table td").not(":first-child")

I would think that the first would be better since it is removes objects, but is there an actual difference and is it substantial.

Thanks

解决方案

Depends on the browser.

Browsers that support querySelectorAll will get a performance boost with...

$("table td:not(:first-child)")

...because it is a valid selector. Older browsers (IE7 and lower) will not.

You need to be careful with the :not() selector though. jQuery (Sizzle) extends it with non-standard selectors, so it's easy to break qSA.

这篇关于使用“:not”之间的性能差异和“.not()”选择器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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