checkbox全选反选

来源:互联网 发布:nvsip相似软件 编辑:程序博客网 时间:2024/05/17 06:43

$(function() {
 $("#check").click(function() {
     if($("#check").attr("checked")==false){
      $("input[name='printBox']").attr("checked",false);
     }
     if($("#check").attr("checked")==true){
      $("input[name='printBox']").attr("checked",true);
     }
 });
 
 $("input[name='printBox']").click(function(){
     var de = document.getElementsByName("printBox");
    
     var num=0;
     for(i = 0; i < de.length; i++){
      if(de[i].checked == true){
       num++;
      }
     }
     if(num==de.length){
      $("#check").attr("checked",true);
     }else{
      $("#check").attr("checked",false);
     }
     });
 });

 

 

 

“#check“表示全选的复选框的id名

”printBox“表示其他复选框的name值