选中/取消选中无复选框

问题描述:

我有一组复选框。一个是条件[]。这个数组的最后一个复选框被命名为“none”。这样,如果用户选择此复选框,则应检查所有其他复选框。选中/取消选中无复选框

我想弄清楚如何编写我的if语句,以便当页面加载和任何其他复选框被选中时,它需要确保没有被检查。反之亦然,如果没有其他复选框被选中,那么我需要确保检查没有的复选框。

请记住,这些是动态创建的,实际上并没有在数据库中。

你的问题不是很清楚。

// you need to add a class('.otherCheckboxClass') to all the checkbox other than the none one. 

var allOtherChecked = true; 
// go trough all checkboxes other than the none one 
$(".otherCheckboxClass").each(function() { 
    // verify if one of them is not checked 
    if(!$(this).is(":checked")){ 
    // if one is checked, set var to false 
    allOtherChecked = false; 
    } 

    // if all of them are checked, add check to the none checkbox. 
    if(allOtherChecked == true){ 
    $('.noneCheckBox').prop("checked", true); 
    } 

});