jquery - 是:text case sensitive?

标签 jquery jquery-selectors

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/

相关文章:

javascript - 如何在不同的 URL 上共享 DISQUS

javascript - 格式化 JSON 数据并将其附加到 html div

jquery - Div Slide 在 Chrome/Safari 中无法正常工作

javascript - 如何存储除下拉菜单之外的类(class)并打开新的文本框放置其他教育?

jquery - jQuery 中需要一个 "HAS A"选择器

javascript - jQuery gt(0) 选择器问题

javascript - 重置 tinymce 工具栏选择

javascript - 使用 :checked selector

jquery - jQuery升级后,未捕获异常: Syntax error,无法识别的表达式:h3

jQuery addClass 只要至少一个后代有类