小小的demo,用js捕捉键盘盘上按下了那个键,然后展示出对应的code值
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 <!DOCTYPE html> <html> <head> <script> function showKeyCode(event) { document.getElementById("result").value= event.keyCode; } </script> </head> <body onkeyup="showKeyCode(event)"> <p>按下键盘上的键,文本框中会显示对应的code</p> <input type="text" id="result" value="1" /> </body> </html>