複製代碼 代碼如下: <BR> function jumpPage() { <BR> if (event.keyCode==37)//左<BR>fun_a(); <BR>if (event.keyCode==38)//上<BR> fun_b(); <BR> if (event.keyCode==39)//右<BR>fun_c(); <BR>if (event.keyCode==40)//下<BR>fun_d();<BR> } <P><BR> <P>function fun_a(){ <BR>window.alert('你按下了左')<BR> } <P>function fun_b(){ <BR>window.alert('你按下了上')<BR>} <P>function fun_c(){ <BR>window.alert('你按下了右') <BR>} <P>function fun_d(){<BR> window.alert('你按下了下') <BR>} <BR>document.onkeydown=jumpPage; <P> HTML code 複製程式碼複製程式碼 程式碼如下所示 按向下鍵 按向下鍵 按向下鍵 按向下鍵 按向上鍵 按向上鍵 按向上鍵 按下向上鍵 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 = ""; } }