Disable button if all checkboxes are unchecked and enable it if at least one is checked

后端 未结 4 1175
轮回少年
轮回少年 2021-02-15 16:12

I have a table with a checkbox in each row and a button below it. I want to disable the button if at least one checkbox is checked.


    
         


        
4条回答
  •  渐次进展
    2021-02-15 16:37

    Try this one:

    let $cbs = $(".myCheckBox").change(function() {
        if ($cbs.is(":checked")){
            // disable #confirmButton if at least one checkboxes were checked
            $("#confirmButton").prop("disabled", false);
        } else {
            // disable #confirmButton if all checkboxes were unchecked
            $("#confirmButton").prop("disabled", true);
        }
    });
    

提交回复
热议问题