输入vs:在jQuery中输入 [英] Input vs :Input in jQuery
问题描述
我不知道为什么人们似乎更喜欢:input
over 输入
作为一个jQuery选择器?基本上,这两行似乎做同样的事情:
$('input:first')。focus $ b $(':input:first')。focus()
使用,我找不到为什么。此外,根据此基准,:input
选择器似乎较慢: http: //jsperf.com/input-vs-input/2
:input
是包含< buttons>
,< textarea>
的jQuery的伪选择器, etc
输入
是一个严格匹配< input>
。
关于:input
的附加注释是信息性的:
因为:input是一个jQuery扩展而不是CSS规范的一部分,所以使用
:input
的查询无法利用由本地DOM querySelectorAll()
方法提供的性能提升。为了在使用:input
选择元素时获得最佳性能,首先使用纯CSS选择器选择元素,然后使用 .filter(:input )
。 - 从 https://api.jquery.com/input-selector/
I wonder why people seems to prefer :input
over input
as a jQuery selector? Basically, this two lines seem to do the same thing :
$('input:first').focus()
$(':input:first').focus()
But second version is more widely use, and I don't find why. Moreover, the :input
selector seem slower according to this benchmark: http://jsperf.com/input-vs-input/2
:input
is pseudo selector by jQuery which includes <buttons>
, <textarea>
, e.t.c
input
is a tag match which strictly matches <input>
.
This additional note about :input
is informative:
Because :input is a jQuery extension and not part of the CSS specification, queries using
:input
cannot take advantage of the performance boost provided by the native DOMquerySelectorAll()
method. To achieve the best performance when using:input
to select elements, first select the elements using a pure CSS selector, then use.filter(":input")
.
--from https://api.jquery.com/input-selector/
这篇关于输入vs:在jQuery中输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!