How can I check multiple check boxes in jQuery?

This question already has an answer here:

  • Setting “checked” for a checkbox with jQuery? 38 answers

  • 这里head_checkbox是顶部标题的id,person类是所有行复选框

     $('#head_checkbox').on('change', function () {
                if ($(this).is(':checked')) {
                    $('.person').attr('checked', true);
                } else {
                    $('.person').attr('checked', false);
                }
            });
    
            $('.person').click(function () {
                var total_length = $('.person').length;
                var total_checked_length = $('.person:checked').length;
    
                if (total_length == total_checked_length) {
                    $('#head_checkbox').attr('checked', true);
                } else {
                    $('#head_checkbox').attr('checked', false);
                }
            });
    

           $('#head_checkbox').click(function () {
                if ($(this).is(':checked')) {
                    $('.person').attr('checked', true);
                } else {
                    $('.person').attr('checked', false);
                }
            });
    
    
            $('.person').click(function () {
                if ($('.person').length == $('.person:checked').length) {
                    $('#head_checkbox').attr('checked', true);
                } else {
                    $('#head_checkbox').attr('checked', false);
                }
            });
    
    链接地址: http://www.djcxy.com/p/12256.html

    上一篇: jquery按钮取消选中复选框

    下一篇: 我如何检查jQuery中的多个复选框?