我不知道为什么人们似乎更喜欢:input over 输入作为一个jQuery选择器?基本上,这两行似乎做同样的事情:
$('input:first')。focus $ b $(':input:first')。focus()使用,我找不到为什么。此外,根据此基准,:input 选择器似乎较慢: http: //jsperf/input-vs-input/2
解决方案:input 是包含< buttons> ,< textarea> 的jQuery的伪选择器, etc
输入是一个严格匹配< input> 。
关于:input 的附加注释是信息性的:
因为:input是一个jQuery扩展而不是CSS规范的一部分,所以使用:input 的查询无法利用由本地DOM querySelectorAll()方法提供的性能提升。为了在使用:input 选择元素时获得最佳性能,首先使用纯CSS选择器选择元素,然后使用 .filter(:input )。- 从 api.jquery/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: jsperf/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 DOM querySelectorAll() 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 api.jquery/input-selector/
更多推荐
输入vs:在jQuery中输入
发布评论