jquery select all checkboxes

前端 未结 19 2731
情书的邮戳
情书的邮戳 2020-12-13 12:36

I have a series of checkboxes that are loaded 100 at a time via ajax.

I need this jquery to allow me to have a button when pushed check all on screen. If more are lo

19条回答
  •  死守一世寂寞
    2020-12-13 13:38

    Use the jquery toggle function. Then you can also perform whatever other changes you may want to do along with those changes... such as changing the value of the button to say "check all" or "uncheck all".

    $(function () {
        $('#selectall').toggle(
            function() {
                $('#friendslist .tf').attr('checked', 'checked');
            },
            function() {
                $('#friendslist .tf').attr('checked', '');
            }
        );
    });
    

提交回复
热议问题