Jquery select all if not disabled

后端 未结 4 682
遥遥无期
遥遥无期 2020-12-18 21:46

I am using the following script to select all checkboxes with a given class.

$(document).ready(function(){ // 1
    // 2
    $(\':checkbox.selectall\').on(\'         


        
4条回答
  •  借酒劲吻你
    2020-12-18 22:04

    Use a combonation of the .not() function and :disabled selector to exclude these.

    $(':checkbox[class='+ $(this).data('checkbox-name') + ']').not(':disabled').prop("checked", $(this).prop("checked"));
    $(':checkbox[class='+ $(this).data('checkbox-name') + ']').not(':disabled').trigger("change");
    

    .not() also exists as a selector as :not() and could be used as follows:

     $(':checkbox[class='+ $(this).data('checkbox-name') + ']:not(:disabled)').prop("checked", $(this).prop("checked"));
     $(':checkbox[class='+ $(this).data('checkbox-name') + ']:not(:disabled)').trigger("change");
    

提交回复
热议问题