html KeyDown 当键盘按下时 获取所按键的Code
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>KeyDown</title> <script type="text/javascript"> window.document.onkeydown = fun; function fun(evt) { evt = (evt) ? evt : window.event evt.preventDefault(); if (evt.keyCode) { document.getElementById('inpcode').value = evt.keyCode document.getElementById('inpval').value = String.fromCharCode(evt.keyCode) } } </script> </head> <body> <div> <input type="text" id="inpcode" /> <input type="text" id="inpval" /> </div> </body> </html>