确定是否使用 jQuery 检查复选框
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13165840/
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
Determine if Checkbox is Checked using jQuery
提问by Hommer Smith
Possible Duplicate:
Check checkbox checked property using jQuery
可能的重复:
使用 jQuery 检查复选框已选中的属性
What is the correct way of accessing a checkbox to check if it's checked? Is it necessary to first check if that element exists in the DOM and then see if is checked or not?
访问复选框以检查它是否被选中的正确方法是什么?是否有必要先检查该元素是否存在于 DOM 中,然后再查看是否被检查?
回答by Pastor Bones
You would use the checked selector along with the is method of Jquery
您将使用选中的选择器以及 Jquery 的 is 方法
if($('#chkbox').is(':checked')){
}
回答by defau1t
You can see if the checkbox is checked by using the following condition.
您可以使用以下条件查看复选框是否已选中。
if( $("input:checked").length == 1 ) {
//Checkbox is selected and Do stuff here
}