获取键盘charCode函数
window.onload = function(){ document.onkeypress = function(evt){ alert(String.fromCharCode(getCharCode(evt))); } } function getCharCode(evt){ var e = evt || window.event; if(typeof e.charCode == 'number'){ return e.charCode; }else{ return e.keyCode; } }