IE中,只有keyCode属性,而FireFox中有which和charCode属性
event.which属性对DOM原生的event.keyCode和event.charCode进行了标准化。
function keypress(e){ e = e || window.event; var currKey = e.which || e.charCode || e.keyCode;var keyName = String.fromCharCode(currKey); console.log("按键码: " + currKey + " 字符: " + keyName); } document.onkeypress = function(e){ keypress(e); }