javascript implements checkbox all in code
- 2020-06-03 05:45:25
- OfStack
Code:
function checkall(checkNames){
var allBoxs = document.getElementsByName(checkNames);
for(var i = 0 ;i<allBoxs.length;i++){
if(allBoxs[i].type == 'checkbox'){
if(allBoxs[i].checked==false){
allBoxs[i].checked = true ;
}else{
allBoxs[i].checked = false ;
}
}
}
}
Method of Use
<a href="" onclick="checkall('goods')"> Future generations </a>
Note: 'goods' is the name of all checkbox that need to be selected
Usage Method
<a href="" id="checkAll"> Future generations </a>
<script>
document.getElementById('checkAll').onclick = function () {
checkall('goods')
};
</script>
Note: 'goods' is the name of all checkbox that need to be selected
The above two methods are summarized in this paper, I hope you can like, if there is a better way, please tell friends, this article continues to update.