JS keyboard up and down key how to trigger function

Source: Internet
Author: User

  This article is mainly about the JS keyboard up and down key how to trigger the function of a detailed analysis of the introduction, the need for friends can come to the reference, I hope to help you.

The code is as follows: <script type= "Text/javascript" >  function jumppage () {      if (event.keycode==37)//left & nbsp Fun_a ();  if (event.keycode==38)//Upper  fun_b ();  if (event.keycode==39)//Right   Fun_c ();  if (event.keycode==40)/down   fun_d ();  }          function fun_a () {  window.alert (' You pressed left ')  }    function fun _b () {  window.alert (' You pressed up ')}    function Fun_c () {  window.alert (' You pressed right ')  }    function Fun_d () { window.alert (' You pressed down ')  }  document.onkeydown=jumppage;   </script>     HTML code  copy code code as follows: <table width= "100%" border= "1" cellspacing= "1" cellpadd ing= "0" id=table> <tr id= "Lineone" style= "Background-color: #00cccc;" > <TD id=aa height= "A" > </td> <td id=aa > Press down key </td> <TD id=cc > Press down key </td> <TD id= DD > Press DOWN ARROW </td> <TD id=ee > Press down key </td> </tr> <tr id= "LiNetwo "tyle=" Background-color: #ffffff; " > <TD id=a height= "A" > </td> <td id=b > Press up key </td> <TD id=c > Press up key </td> <TD Id=d & gt; Press up ARROW </td> <TD id=e > Press up key </td> </tr></table><script language= "JavaScript" > function KeyDown (e) {var iekey=event.keycode; action (Iekey);} document.onkeydown = KeyDown; function Action (Iekey) {if (iekey==40) {lineone.style.backgroundColor = ""; Linetwo.style.backgroundColor = "#00cccc"; } if (iekey==38) {lineone.style.backgroundColor = "#00cccc"; linetwo.style.backgroundColor = "";}} </script><input name= "id" type= "hidden" id= "id" value    
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.