W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>在输入栏中按键盘上的任意键可以得到 Unicode 字符代码和被按下键的 Unicode 键盘代码。</p> <p><b>注释:</b>keyCode 属性对不可打印的功能键(如 CAPS LOCK、CTRL、ESC、F12 等)的 onkeypress 事件不起作用。</p> <input type="text" size="50" onkeypress="uniCharCode(event)" onkeydown="uniKeyCode(event)"> <p>onkeypress - <span id="demo"></span></p> <p>onkeydown - <span id="demo2"></span></p> <script> function uniCharCode(event) { var char = event.which || event.keyCode; document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char; } function uniKeyCode(event) { var key = event.keyCode; document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key; } </script> </body> </html>