jquery select all checkboxes

前端 未结 19 2727
情书的邮戳
情书的邮戳 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:34

    I know I'm revisiting an old thread, but this page shows up as one of the top results in Google when this question is asked. I am revisiting this because in jQuery 1.6 and above, prop() should be used for "checked" status instead of attr() with true or false being passed. More info here.

    For example, Henrick's code should now be:

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

提交回复
热议问题