jQuery :text 选择器区分大小写吗?
例如:
<input type="TEXT">
不匹配但是:
<input type="text">
匹配。
情况似乎确实如此。我只是在寻找验证。
编辑
看起来甚至 [type=text] 选择器在 Chrome 和 Firefox 中也区分大小写,但在 IE8 中不区分大小写(在 IE8 文档模式下)
最佳答案
编辑:尽管我进行了研究,但我一开始还是得出了完全错误的结论。答案已更新:O(kudo 转到@ThiagoSantos,他从一开始就给出了正确的答案:D)。
jQuery ":text" documentation状态:
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.
如果您深入了解source of 1.7.1看来这个选择器的实现如下:
text: function( elem ) {
var attr = elem.getAttribute( "type" ), type = elem.type;
// IE6 and 7 will map elem.type to 'text' for new HTML5 types (search, etc)
// use getAttribute instead to test this case
return elem.nodeName.toLowerCase() === "input" && "text" === type && ( attr === type || attr === null );
}
对于<input type="tEXt" />
attr
的值结果是“tEXt”,与 type
不匹配。令我自己惊讶的是:
更新后的答案应该是::文本区分大小写
关于jquery - 是:text case sensitive?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8481480/