最简洁的代码,可以参考一下!
function checkall(){
var hobby = document.getElementsByTagName("input");
for(var i = 0; i < hobby.length; i++){
if(hobby[i].name == "hobby"){
hobby[i].checked = true;
}
}
}
function clearall(){
var hobby = document.getElementsByName("hobby");
for(var i = 0; i < hobby.length; i++){
if(hobby[i].name == "hobby"){
hobby[i].checked = false;
}
}
}
function checkone(){
var j=document.getElementById("wb").value;
var hobby = document.getElementById("hobby" + j);
if(hobby){
hobby.checked = true;
}else{
alert("没有改选项");
}
}