[读码时间] 按下键盘显示keyCode
说明:代码取自网络
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title>按下键盘显示keyCode</title> <style> body{ text-align:center; font:30px/1.5 \5fae\8f6f\96c5\9ed1,arial; } pre{ color:green; padding:10px 15px; background:#f0f0f0; border:1px dotted #333; font:12px/1.5 Courier New; text-align:left; } span{ color:#999; } </style> <script> window.onload = function () { var oP = document.getElementsByTagName("p")[0]; document.onkeydown = function (event) { var event = event || window.event; oP.innerHTML = event.keyCode; return false; } } </script> </head> <body> <pre> <script type="text/javascript"> window.onload = function () { var oP = document.getElementsByTagName("p")[0]; document.onkeydown = function (event) { var event = event || window.event; oP.innerHTML = event.keyCode; return false } } </script></pre> <p>这里将显示您按下键的 keyCode</p> </body> </html>