jQuery 获取复选框jquery的当前状态

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23911602/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:24:23  来源:igfitidea点击:

get current state of check box jquery

jqueryjquery-uitwitter-bootstrap

提问by user3316523

I am using Bootstrap iCheckplugin. How can i find out Whether a check box is checked or not by pressing a button using jquery

我正在使用 Bootstrap iCheck插件。如何通过使用 jquery 按下按钮来确定复选框是否被选中

$(button).click(function(){

  ckb = $("#ickb").(isChecked);
});

回答by Balachandran

Try to use .is()function along with :checkedselector to accomplish your task,

尝试使用.is()函数和:checked选择器来完成你的任务,

ckb = $("#ickb").is(':checked');

回答by Adil

Use is()with :checkedto get the result as boolean that is true if checkbox is checked.

is():checked一起使用以将结果作为布尔值,如果复选框被选中则为 true。

ckb = $("#ickb").is(':checked');

Or, you can use length, if it is zerothen it is not checked.

或者,您可以使用长度,如果它为零,则不会检查它。

ckb = $("#ickb::checked").length