Har*_*tor 12 css jquery jquery-selectors
我不知道为什么人们似乎更喜欢:input
在input
一个jQuery选择?基本上,这两行似乎做同样的事情:
$('input:first').focus()
$(':input:first').focus()
Run Code Online (Sandbox Code Playgroud)
但第二版更广泛使用,我找不到原因.而且,:input
根据这个基准测试选择器似乎更慢:http://jsperf.com/input-vs-input/2
Sel*_*gam 19
:input
是通过jQuery的伪选择器,其中包括<buttons>
,<textarea>
等
input
是一个严格匹配的标签匹配<input>
.
这篇补充说明内容:input
丰富:
因为:input是jQuery扩展而不是CSS规范的一部分,使用的查询
:input
无法利用本机DOMquerySelectorAll()
方法提供的性能提升.要在使用:input
选择元素时获得最佳性能,首先使用纯CSS选择器选择元素,然后使用.filter(":input")
.
- 来自https://api.jquery.com/input-selector/
归档时间: |
|
查看次数: |
2313 次 |
最近记录: |