站长资源网络编程

onkeypress字符按键兼容所有浏览器使用介绍

整理:jimmy2026/8/6浏览2
简介复制代码 代码如下: document.onkeypress = function( e ){ alert( getCharCode( e ) ); }; function getCharCode( e ){ var e = e || window.event; if( typeof e.charC
复制代码 代码如下:
document.onkeypress = function( e ){
alert( getCharCode( e ) );
};
function getCharCode( e ){
var e = e || window.event;
if( typeof e.charCode == "number" ){
return e.charCode;
}else{
return e.keyCode;
};
};