select all checkbox only works twice

前端 未结 5 973
误落风尘
误落风尘 2021-01-14 02:28

I got this code from stackoverflow which looks like a pretty good \"select all\" checkbox solution, any ideas why it fails after 2nd click?

http://jsfiddle.net/R9zj

5条回答
  •  既然无缘
    2021-01-14 03:15

    some problem is solved see the live demo at here

    HTML code is:

    select all

    and Javascript is:

    $(document).ready(function () {
        $(document).on("click", ".selectall2", function () {
            $(this).closest('tr').find('input[type=checkbox]').attr('checked', this.checked);
        });
        $(document).on("click",".abc",function(){
            var temp=0;
            if(!$(".abc").attr('checked'))
            {
                temp=1;
            }
            if(temp==0)
            {
                        $(".selectall2").attr('checked',true);
            }
            else
            {
                        $(".selectall2").attr('checked',false);
            }
        });
    });
    

提交回复
热议问题