如何实现全选和全不选

<!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>
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值