全选及取消全选

<html>
<head>
<title>mock</title>
<script src="jquery.js"></script>
</head>
<body>

<input type="checkbox" value="1" id="a" />1

<input type="checkbox" value="2" id="b" />2

<input type="checkbox" value="3" id="c" />3


<input type="button" value="全选" id="bb" />
<input type="button" value="取消" id="cc" />


<script>

$("#a, #b, #c").change(function(){

    console.log(this.value + " 状态 " + this.checked)

})

$("#bb").click(function(){
    
    $("#a, #b, #c").each(function(){
        this.checked=true;
    }).change()

})
$("#cc").click(function(){
    
    
    $("#a, #b, #c").each(function(){
        this.checked=false;
    }).change()

})


</script>




</body>
</html>

 

posted @ 2017-07-24 09:28  boyanh  阅读(434)  评论(0编辑  收藏  举报