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

后端 未结 4 1189
轮回少年
轮回少年 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:47

    Try this:

    $('tbody').click(function () {
    
       if ($('.myCheckBox:checked').length >= 1) { 
               $('#confirmButton').prop("disabled", true);
           }
       else {
                $('#confirmButton').prop("disabled", false);
       } 
    
     });
    

    DEMO

提交回复
热议问题