jquery实现全选、全消、反选功能

HTML代码:  

  

<input type="checkbox" name="checkbox" class="A"  />

使用按钮来实现全选、全消、反选

<button  id="checkAll">全选</button  >
<button   id="removeAll">全消</button  >
<button   id="reverse">反选</button  >

  jquery代码要求:1.项目中必须引入jquery,2.必须在<script></script>之中写

      // 全选
      $("#checkAll").click(function() {
          $(".A").prop('checked',true);
      });
      // 全消
      $("#removeAll").click(function() {
          $(".A").prop('checked',false);
      });

      // 反选
      $("#reverse").click(function(){
          $(".A").each(function(){
              $(this).prop('checked',!$(this).prop('checked'));
          })
      });

  

  

原文地址:https://www.cnblogs.com/Worssmagee1002/p/6734902.html