js中对按键的监听

2019PHP高薪工程师学习路线图....>>>

js中,实现对键盘按键的监听:

function keyUp> 这里输入引用文本p(e) {   
       var currKey=0,e=e||event;   
       currKey=e.keyCode||e.which||e.charCode;   
       var keyName = String.fromCharCode(currKey);   
       alert("按键码: " + currKey + " 字符: " + keyName);   
   }   
document.onkeyup = keyUp;

alert信息例如:"按键码: 81 字符: Q"