Check all other checkboxes when one is checked

后端 未结 10 817
感情败类
感情败类 2020-12-09 23:11

I have a form and group of checkboxes in it. (These checkboxes are dynamically created but I dont think it is important for this question). The code that generates them look

10条回答
  •  孤街浪徒
    2020-12-09 23:21

    You can use jQuery like so:

    jQuery

    $('[name="ALL"]:checkbox').change(function () {
       if($(this).attr("checked")) $('input:checkbox').attr('checked','checked');
       else $('input:checkbox').removeAttr('checked');
    });
    

    A fiddle.

提交回复
热议问题