有没有办法用 CSS 选择多个输入字段类型?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7474057/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to select multiple input field types with CSS?
提问by Joanna
I have a text and a password input field that I'm trying to select in this fashion:
我有一个文本和一个密码输入字段,我试图以这种方式选择:
input[type=text][type=password]
however this does not work. I would refrain from using jQuery, so any help would be appreciated (without using custom classes).
但是这不起作用。我会避免使用 jQuery,所以任何帮助将不胜感激(不使用自定义类)。
回答by BoltClock
You need to specify the attributes separately, repeating the types if necessary and using comma(s):
您需要单独指定属性,必要时重复类型并使用逗号:
input[type=text], input[type=password]
Your given selector is trying to match an input
with a type
that is both text
and password
, but a single element can't have different values for the same attribute so it fails.
您给定的选择器正试图将 aninput
与type
既是text
and 的a相匹配password
,但单个元素的同一属性不能具有不同的值,因此它失败了。