The checkone () function code block in the following js code is solved!

<!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.

Mar.20,2021

        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="";
                    return;//return
                }
            }
            // 
                for(var n=0;n<j.length;nPP){
                   
                        hobby[(j.charAt(n))-1].checked=true; 
                }

            
            
        }

where is the fan, there is something wrong with this code, if it does not comply with the rules, it will continue to execute, and it will report an error.


function checkone() {
    clearall(); // 
    var hobby = document.getElementsByName("hobby"); //  array
    var j = document.getElementById("wb").value; //  index
    for (var i = 0; i < j.length; iPP) { //  136136
        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; // 
    }
}

it is possible that the input value is 432, so check items 2, 3, 4

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b36d48-343f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b36d48-343f5.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?