获取键盘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;
    }
}
原文地址:https://www.cnblogs.com/oceanden/p/3928046.html