运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>Keyboard Events</h1> <h2>The key Property</h2> <p>Press the "A" key on the keyboard in the input field!</p> <input type="text" size="40" onkeydown="myFunction(event)"> <p id="demo"></p> <script> function myFunction(event) { let key = event.key; if (key == "a" || key == "A") { let text = "You pressed the 'A' key!"; document.getElementById("demo").innerHTML = text; } } </script> </body> </html>