先导入jquery组件

<input type="checkbox" >反选
<input type="checkbox" name="check1">1
<input type="checkbox" name="check1">2

<script>  
$(function(){  
    $("#checkall").click(function(){
        $('[name=check1]:checkbox').attr('checked',this.checked);//checked为true时为默认显示的状态   
    });  
    $("#checkrev").click(function(){  
        //实现反选功能  
        $('[name=check1]:checkbox').each(function(){  
            this.checked=!this.checked;  
        });  
    });   
});  
</script>

一个按钮实现全选和反选

<input type="checkbox" id="checkall">全选
<input type="checkbox" name="check1">1
<input type="checkbox" name="check1">2

<script>  
$(function(){  
    $("#checkall").click(function(){
        $('[name=check1]:checkbox').each(function(){  
            this.checked=!this.checked;
        });
    });  
});  

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2021-12-27
  • 2022-12-23
猜你喜欢
  • 2018-01-16
  • 2021-10-22
  • 2021-05-21
  • 2022-12-23
  • 2021-12-11
  • 2021-06-17
  • 2021-11-06
相关资源
相似解决方案