运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>Keyboard Events</h1> <h2>The location Property</h2> <p>Press any key on the keyboard in the input field to get the location of the key.</p> <input type="text" size="40" onkeydown="myFunction(event)"> <p>Possible return values:</p> <ul> <li>0: A standard key (like "A")</li> <li>1: A left key (like left CTRL)</li> <li>2: A right key (like right CTRL)</li> <li>3: A key on the numeric keypad</li> </ul> <p id="demo"></p> <script> function myFunction(event) { let location = event.location; document.getElementById("demo").innerHTML = "Location: " + location; } </script> </body> </html>