W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>在输入字段中按键盘上的某个键可获取被按下键的数字和字符。</p> <input type="text" size="40" onkeypress="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) { var x = event.charCode || event.keyCode; // 获取 Unicode 值 var y = String.fromCharCode(x); // 将值转换为字符 document.getElementById("demo").innerHTML = "Number: " + x + " = Character: " + y; } </script> </body> </html>