其他分享
首页 > 其他分享> > 如何实现全选和全不选

如何实现全选和全不选

作者:互联网

<!DOCTYPE html>
<html lang="en">
<head>    
<meta charset="UTF-8">    
<meta name="viewport" content="width=device-width, initial-scale=1.0">    
<meta http-equiv="X-UA-Compatible" content="ie=edge">    
<title>Document</title>
</head>
<body>    
<input type="checkbox" id="ck1"> 全选/反选<br>   
 <div>        
 <input type="checkbox" id="ck2">JavaScript        
 <input type="checkbox" id="ck3">NodeJS        
 <input type="checkbox" id="ck4">vue        
 <input type="checkbox" id="ck5">react        
 <input type="checkbox" id="ck6">angular    
 </div>
    <script>        
    var ck1 = document.getElementById('ck1');        
    var ck2 = document.getElementById('ck2');       
     var ck3 = document.getElementById('ck3');       
      var ck4 = document.getElementById('ck4');        
      var ck5 = document.getElementById('ck5');      
        var ck6 = document.getElementById('ck6');
        ck1.onclick = function () {           
         if (ck1.checked == true) {                
         ck2.checked = true;                
         ck3.checked = true;               
          ck4.checked = true;                
          ck5.checked = true;                
          ck6.checked = true;            
          } else {                
          ck2.checked = false;                
          ck3.checked = false;                
          ck4.checked = false;                
          ck5.checked = false;                
          ck6.checked = false;           
           }       
            };


    </script>
    </body>
</html>

标签:checked,如何,getElementById,全选,全不选,var,false,document,true
来源: https://blog.csdn.net/liuliyueliuli/article/details/100066031