checkbox全选和全部选

<input type="checkbox" class="form-control" id="checkAll" onclick="CheckboxAll()"/>


<input type="checkbox" class="form-control checkbox" />

<input type="checkbox" class="form-control checkbox" />

<input type="checkbox" class="form-control checkbox" />

<input type="checkbox" class="form-control checkbox" />

..............

<script>

 //全选和全不选
 function CheckboxAll(){
     var checkAll = document.getElementById("checkAll");
     var checkInput = document.getElementsByClassName("checkbox");
    if(checkAll.checked){
        for(var i=0;i<checkInput.length;i++){
            checkInput[i].checked = true;
        }
    }else{
        for(var i=0;i<checkInput.length;i++){
            checkInput[i].checked = false;
        }
    }

 }



</script>

猜你喜欢

转载自blog.csdn.net/czp555/article/details/76641340