javascript捕捉键盘
1 <!DOCTYPE html> 2 <html lang="en"> 3 4 <head> 5 <meta charset="UTF-8"> 6 <meta http-equiv="X-UA-Compatible" content="IE=edge"> 7 <meta name="viewport" content="width=device-width, initial-scale=1.0"> 8 <title>Document</title> 9 </head> 10 11 <body> 12 <script> 13 window.onload = function () { 14 let usernameElt = document.getElementById("username"); 15 usernameElt.onkeydown = function (event) { 16 alert(event.key); 17 } 18 } 19 </script> 20 <input type="text" name="" id="username"> 21 </body> 22 23 </html>