This article mainly introduces the use of JS to control the keyboard up and down key sample code. Need friends can come to the reference, I hope to help you.
This is a JS primary code, want to learn JS friend, you can study under or expand, it is best to use JS to achieve the entire keyboard control, that feeling is very interesting. Specific code as follows: code as follows: <style> tr.highlight{background: #08246B; color:white} </style> <table Border= "1" width= "70%" id= "ice" > <tr> <td><input type= ' text ' ></td> <td><input Type= ' text ' ></td> <td><input type= ' text ' ></td> <td><input type= ' text ' ></ td> </tr> <tr> <td><input type= ' text ' ></td> <td><input type= ' text ' >< /td> <td><input type= ' text ' ></td> <td><input type= ' text ' ></td> </tr> <tr> <td><input type= ' text ' ></td> <td><input type= ' text ' ></td> <td> <input type= ' text ' ></td> <td><input type= ' text ' ></td> </tr> <tr> <td ><input type= ' text ' ></td> <td><input type= ' text ' ></td> <td><input type= ' Text ' ></td> <TD><input type= ' text ' ></td> </tr> <tr> <td><input type= ' text ' ></td> <TD ><input type= ' text ' ></td> <td><input type= ' text ' ></td> <td><input type= ' Text ' ></td> </tr> </table> <script language= "JavaScript" > <!--//define initialization row Var CurrentLine =-1; var currentcol=-1; Document.onkeydown=function (e) { E=window.event| | E Switch (e.keycode) { case 37://Left currentcol--; Changeitem () ; break; Case 38://Up key currentline--; Changeitem (); break; CASE 39://Right button currentcol++; Changeitem (); break; CASE 40://Down key currentline++; Changeitem (); break; Default: break; }//arrow keys Invoke function Changeitem () { if (document.all) var it=document.getelementbyidx_x ("Ice"). CHILDREN[0]; Else var it=document.getelementbyidx_x ("Ice"); for (i=0;i<it.rows.length;i++) { it.rows[i].classname= ""; } if (currentline<0) {& nbsp Currentline=it.rows.length-1; } if (currentline==it.rows.length) { currentline=0 } var objtab=document.all.ice; var objrow=objtab.rows[currentline].getelementsbytagname_r ("INPUT"); if (currentcol<0) { currentcol=objrow.length-1 }else if (currentcol==objrow.length) { currentcol=0; } Objrow[currentcol].select (); //Commissioning use it.rows[currentline].classname= "highlight"; }//--> </script>