我使用函数each()循环遍历具有相同类的多个复选框,并且在循环中,我需要能够判断复选框是否被选中。如何做到这一点?
$('.checkbox').each(function() {
var is_checked = 'no';
// I need to change the value of the is_checked variable to 'yes'
// if the checkbox is checked
//
});发布于 2009-11-04 05:19:43
使用
var is_checked = this.checked ? 'yes' : 'no';发布于 2009-11-04 05:24:09
一种方法是:
$('#yourcheckbox').is(':checked'); 发布于 2009-11-04 05:24:09
为什么不使用:checkbox:checked选择器呢?这样,您就可以获得所有选中的复选框的列表,并遍历这些复选框。
https://stackoverflow.com/questions/1670192
复制相似问题