Html+JS實現全選與非全選操作
阿新 • • 發佈:2019-02-14
看書:<input type="checkbox" name="checkbox" value=1><br>
寫字:<input type="checkbox" name="checkbox"value=2><br>
玩遊戲:<input type="checkbox" name="checkbox"value=4><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="";
}
}
}