Select All checkboxes using jQuery

前端 未结 15 1576
渐次进展
渐次进展 2020-12-05 06:26

I have the following html code:

    
    

相关标签:
15条回答
  • 2020-12-05 07:09

    Try the following simple code:

    $('input[type=checkbox]').each(function() { this.checked = true; }); 
    

    Source: How to reset all checkboxes using jQuery or pure JS?

    0 讨论(0)
  • 2020-12-05 07:10

    Try this

    $(document).ready(function () {
        $("#ckbCheckAll").click(function () {
            $("#checkBoxes input").prop('checked', $(this).prop('checked'));
        });
    });
    

    That should do it :)

    0 讨论(0)
  • 2020-12-05 07:13
    $(document).ready(function() {
        $('#ckbCheckAll').click(function() {
            $('.checkBoxClass').each(function() {
                $(this).attr('checked',!$(this).attr('checked'));
            });
        });
    });
    

    OR

    $(function () {
        $('#ckbCheckAll').toggle(
            function() {
                $('.checkBoxClass').prop('checked', true);
            },
            function() {
                $('.checkBoxClass').prop('checked', false);
            }
        );
    });
    
    0 讨论(0)
提交回复
热议问题