📌  相关文章
📜  如何在javascript代码示例中获取按下了哪个键

📅  最后修改于: 2022-03-11 15:01:31.335000             🧑  作者: Mango

代码示例2
function myKeyPress(e){
  var keynum;

  if(window.event) { // IE                  
    keynum = e.keyCode;
  } else if(e.which){ // Netscape/Firefox/Opera                 
    keynum = e.which;
  }

  alert(String.fromCharCode(keynum));
}