JS全选反选功能

总选框:<input type="checkbox" class="all" name="all">

子选框:
<input class='sel' type='checkbox' name='test' value="">




/**
             * 全选 反选
             */
            $(".all").bind("click",function(){
            $(".sel").prop("checked",$(this).prop("checked"));
            })
            $(".sel").bind("click",function(){
                var sel=$(".sel");
                var b=true;
                for(var i=0;i<sel.length;i++){
                    if(sel[i].checked==false){
                        b=false;
                        break;
                    }
                }
                $(".all").prop("checked",b);
            })

  

猜你喜欢

转载自www.cnblogs.com/pxblog/p/10783044.html