Home  >  Article  >  Web Front-end  >  onkeypress character keys are compatible with all browsers usage introduction_javascript skills

onkeypress character keys are compatible with all browsers usage introduction_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:35:201296browse
Copy code The code is as follows:

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;
};
};
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn