checkbox之全选和反选

Posted 三体

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了checkbox之全选和反选相关的知识,希望对你有一定的参考价值。

先导入jquery组件

<input type="checkbox" id="checkall">全选<input type="checkbox" id="checkrev">反选
<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>

  

以上是关于checkbox之全选和反选的主要内容,如果未能解决你的问题,请参考以下文章