คัดลอกรหัสรหัสดังต่อไปนี้:
<script type="text/javascript">
ฟังก์ชั่น JumpPage() {
ถ้า (event.keyCode==37)//left
fun_a();
ถ้า (event.keyCode==38)//Up
fun_b();
ถ้า (event.keyCode==39)//right
fun_c();
ถ้า (event.keyCode==40)//ถัดไป
กองทุน();
-
ฟังก์ชั่น fun_a(){
window.alert('คุณกดซ้าย')
-
ฟังก์ชั่น fun_b(){
window.alert('คุณกดขึ้น')
-
ฟังก์ชั่น fun_c(){
window.alert('คุณกดขวา')
-
ฟังก์ชั่น fun_d(){
window.alert('คุณกดแล้ว')
-
document.onkeydown=jumpPage;
</สคริปต์>
รหัส HTML
คัดลอกรหัสรหัสดังต่อไปนี้:
<table cellspacing="1" cellpadding="0" id=table> <tr id="lineone" style="พื้นหลัง-สี:#00cccc;"> <td id=aa></td> <td id=aa >กดปุ่มลง</td> <td id=cc >กดปุ่มลง</td> <td id=dd >กดปุ่มลง</td> <td id=ee >กดปุ่มลง</td > </tr> <tr id="linetwo" tyle="พื้นหลัง-สี:#ffffff;"> <td id=a></td> <td id=b >กดปุ่มขึ้น</td> <td id = c >กดปุ่มขึ้น</td> <td id=d >กดปุ่มขึ้น</td> <td id=e >กดปุ่มขึ้น</td> </tr></table><ภาษาสคริปต์ ="จาวาสคริปต์"> ฟังก์ชัน keyDown(e) { var iekey=event.keyCode; action(iekey); } document.onkeydown = keyDown; ฟังก์ชัน การกระทำ(iekey) { if(iekey==40) { lineone.style.wallpaper = ""; .พื้นหลังสี = "#00cccc"; } if(iekey==38) { lineone.style.พื้นหลังสี = "#00cccc"; linetwo.style.พื้นหลังสี = ""; } } </script><input name="id" type="hidden" id="id" ค่า