输入vs:在jQuery中输入

编程入门 行业动态 更新时间:2024-10-26 01:26:45
本文介绍了输入vs:在jQuery中输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我不知道为什么人们似乎更喜欢: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中输入

本文发布于:2023-08-01 18:39:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1270695.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:jQuery

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!