checkbox全選和全部選

<input type="checkbox" class="form-control" id="checkAll" οnclick="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>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章