<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DOM </title>
</head>
<body>
<form>
:<br>
<input type="checkbox" name="hobby" id="hobby1">
<input type="checkbox" name="hobby" id="hobby2">
<input type="checkbox" name="hobby" id="hobby3">
<input type="checkbox" name="hobby" id="hobby4">
<input type="checkbox" name="hobby" id="hobby5">
<input type="checkbox" name="hobby" id="hobby6"> <br/>
<input type="button" value = "" onclick = "checkall();">
<input type="button" value = "" onclick = "clearall();">
1-6:
<input id="wb" name="wb" type="text" >
<input name="ok" type="button" value="" onclick = "checkone();">
</form>
<script type="text/javascript">
function checkall(){
var hobby = document.getElementsByName("hobby");
for(var i=0;i<hobby.length;iPP){
hobby[i].checked=true; //
}
}
function clearall(){
var hobby = document.getElementsByName("hobby");
//alert(hobby.length);
for(var i=0;i<hobby.length;iPP){
hobby[i].checked=false;
}
}
function checkone(){ //
clearall();
var hobby = document.getElementsByName("hobby");
var j=document.getElementById("wb").value;
for(var i=0;i<j.length;iPP){
if(j.charAt(i)>6 || j.charAt(i)<1){
alert(",");
document.getElementById("wb").value="";
}
}
for(var n=0;n<j.length;nPP){
hobby[(j.charAt(n))-1].checked=true;
}
}
</script>
</body>
</html>
as above, the code block of the checkone () function in the code is solved! The statements in the for loop, in particular, are a bit of a mystery.