[英]Jquery $(:text) and $(input[type="text"])
$(:text)
和$(input[type="text"])
Jquery选择器之间有什么区别。
As of jQuery 1.5.2, :text selects input elements that have no specified type attribute (in which case type="text" is implied).从 jQuery 1.5.2 开始, :text 选择没有指定类型属性的输入元素(在这种情况下 type="text" 是隐含的)。
This difference in behavior between $( ":text" ) and $( "[type=text]" ), can be seen below: $( ":text" ) 和 $( "[type=text]" ) 之间的行为差异如下所示:
$( "<input>" ).is( "[type=text]" ); // false
$( "<input>" ).is( ":text" ); // true
Additional Notes:补充说明:
Because :text is a jQuery extension and not part of the CSS specification, queries using :text cannot take advantage of the performance boost provided by the native DOM querySelectorAll() method.因为 :text 是 jQuery 扩展而不是 CSS 规范的一部分,所以使用 :text 的查询无法利用原生 DOM querySelectorAll() 方法提供的性能提升。 For better performance in modern browsers, use [type="text"] instead.
为了在现代浏览器中获得更好的性能,请改用 [type="text"]。 https://api.jquery.com/text-selector/
https://api.jquery.com/text-selector/
$(input[type="text"])
will select all the input tags which have the type specified $(input[type="text"])
将选择具有指定类型的所有输入标签
$(:text)
will select all the input tags which have the type specified or not defined $(:text)
将选择所有具有指定类型或未定义类型的输入标签
<input type="text" name="text1" value="abc" />
<input name="text2" value="xyz" />
$(input[type="text"])
will select the first input tag only $(input[type="text"])
将只选择第一个输入标签
$(:text)
will select both input tages $(:text)
将选择两个输入标签
check js fiddle demo检查js小提琴演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.