Use JS to control the keyboard up and down key

Source: Internet
Author: User

  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>  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.