W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <p>在输入字段中按键盘上的某个键,以确定是否按下了 ALT 键。</p> <input type="text" onkeydown="isKeyPressed(event)"> <p id="demo"></p> <script> function isKeyPressed(event) { var x = document.getElementById("demo"); if (event.altKey) { x.innerHTML = "The ALT key was pressed!"; } else { x.innerHTML = "The ALT key was NOT pressed!"; } } </script> </body> </html>