Js keyboard up and down key about how to trigger function of instance
- 2020-03-30 00:51:17
- OfStack
<script type="text/javascript">
function jumpPage() {
if (event.keyCode==37)// On the left
fun_a();
if (event.keyCode==38)// on
fun_b();
if (event.keyCode==39)// right
fun_c();
if (event.keyCode==40)// Under the
fun_d();
}
function fun_a(){
window.alert(' You hit left ')
}
function fun_b(){
window.alert(' You press up ')
}
function fun_c(){
window.alert(' You press right ')
}
function fun_d(){
window.alert(' You hit the button ')
}
document.onkeydown=jumpPage;
</script>
HTML code
<table width="100%" border="1" cellspacing="1" cellpadding="0" id=table> <tr id="lineone" style="background-color:#00cccc;"> <td id=aa height="23"> </td> <td id=aa > Press the down key </td> <td id=cc > Press the down key </td> <td id=dd > Press the down key </td> <td id=ee > Press the down key </td> </tr> <tr id="linetwo" tyle="background-color:#ffffff;"> <td id=a height="23"> </td> <td id=b > Press the up button </td> <td id=c > Press the up button </td> <td id=d > Press the up button </td> <td id=e > Press the up button </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