<html>:
看书:<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>
<button οnclick="checkboxed('checkbox')">全选</button>
<button οnclick="uncheckboxed('checkbox')">取消全选</button>
<javascript>:
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="";
}
}
}