javascript 选择所有类型不是复选框的输入标签
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9956545/
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
Select all input tags where type is not checkbox
提问by daGrevis
I need CSS selector that match all input tags where type is notcheckbox
.
我需要匹配所有输入标签的 CSS 选择器,其中 type不是checkbox
。
This match:
这场比赛:
<input value="Meow!" />
<input value="Meow!" />
<input type="password" />
<input type="password" />
...but this does not:
...但这不是:
<input type="checkbox" />
<input type="checkbox" />
Because type is checkbox
!
因为类型是checkbox
!
This is what I have at the moment:
这就是我目前所拥有的:
input:not(type="checkbox")
input:not(type="checkbox")
Unfortunately, it does notwork!
不幸的是,它并没有工作!
So here comes my questions:
所以我的问题来了:
- How to fix my CSS3 selector?
- Is it possible without CSS3 and JavaScript?
- Is it possible without CSS3, but with use of JavaScript?
- 如何修复我的 CSS3 选择器?
- 没有 CSS3 和 JavaScript 有可能吗?
- 没有 CSS3,但使用 JavaScript 是否可能?
Thanks in any advice!
感谢任何建议!
回答by BoltClock
Your attribute selector is missing the square brackets:
input:not([type="checkbox"])
If you're applying styles you will need to make use of an override rule in CSS:
input { /* Styles for all inputs */ } input[type="checkbox"] { /* Override and revert above styles for checkbox inputs */ }
As you can imagine, it's almost impossible to do this for form elements because their browser-default styles aren't well-defined in CSS.
jQuery provides a
:checkbox
selectorthat you can use:$('input:not(:checkbox)')
You can also use the same selector as you do in CSS:
$('input:not([type="checkbox"])')
您的属性选择器缺少方括号:
input:not([type="checkbox"])
如果要应用样式,则需要使用 CSS 中的覆盖规则:
input { /* Styles for all inputs */ } input[type="checkbox"] { /* Override and revert above styles for checkbox inputs */ }
可以想象,对表单元素执行此操作几乎是不可能的,因为它们的浏览器默认样式在 CSS 中没有明确定义。
jQuery 提供了一个可以使用的
:checkbox
选择器:$('input:not(:checkbox)')
您还可以使用与在 CSS 中相同的选择器:
$('input:not([type="checkbox"])')
回答by Alexander Pavlov
input:not([type="checkbox"])
input:not([type="checkbox"])