【发布时间】:2019-04-09 05:49:05
【问题描述】:
两者之间是否存在性能差异:
$("#divId :input")
和
$("#divId").find(":input")
和
$(":input", "#divId")
这里描述了最后一个变体https://api.jquery.com/jQuery/#jQuery-selector-context
【问题讨论】:
-
根据jQuery documentation:
Internally, selector context is implemented with the .find() method, so $( "span", this ) is equivalent to $( this ).find( "span" ).根据this test,find()看起来比后代选择器快。 -
需要注意的是,
children()选项不保证是测试中前两个操作的 1:1 结果集。 @showdev -
@showdev 非常有趣。谢谢。
标签: jquery performance