input checkbox 全选与取消全选

时间:2022-06-01 16:58:26
看书:<input type="checkbox" name="checkbox" value=1><br>
写字:<input type="checkbox" name="checkbox"value=2><br>
打飞机:<input type="checkbox" name="checkbox"value=3><br>
玩游戏:<input type="checkbox" name="checkbox"value=4><br>
sing游戏:<input type="checkbox" name="checkbox"value=5><br>
<button onclick="checkboxed('checkbox')">全选</button>

<button onclick="uncheckboxed('checkbox')">取消全选</button>


function checkboxed(objName){
var objNameList=document.getElementsByName(objName);


if(null!=objNameList){
alert("全选操作");
for(var i=0;i<objNameList.length;i++){
objNameList[i].checked="checked";
}
}
}


function uncheckboxed(objName){
var objNameList=document.getElementsByName(objName);


if(null!=objNameList){
alert("取消全选操作");
for(var i=0;i<objNameList.length;i++){
objNameList[i].checked="";
}
}
}