未禁用的所有选中复选框的 jquery 选择器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12358231/
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
jquery selector for all checked checkboxes that are not disabled
提问by forkie
how can I find all checkboxes, that are checked and not disabled?
如何找到所有已选中但未禁用的复选框?
采纳答案by Hoffmann
$('input[type="checkbox"]').filter(function() {
return !this.disabled && this.checked;
})
回答by Eric
Like so:
像这样:
$("input[type='checkbox']:checked").not(":disabled")...
This finds fields that are input
s, with type checkbox
, which are checked, and not disabled. If this does not work, you should use an attribute check:
这将查找input
s、类型checkbox
为已选中且未禁用的字段。如果这不起作用,您应该使用属性检查:
$("input[type='checkbox']:checked").not("[disabled]")...
Or, as @lonesomeday astutely pointed out, you can combine it into one selector:
或者,正如@lonesomeday 敏锐地指出的那样,您可以将其合并为一个选择器:
$("input[type='checkbox']:checked:not(:disabled)")...
I've put together a proof-of-concept in this fiddle.
我在这个 fiddle 中整理了一个概念验证。
回答by Sushanth --
回答by Erico Chan
how about $("input[type='checkbox']:checked:enabled")
?
怎么样$("input[type='checkbox']:checked:enabled")
?