Created
March 17, 2019 15:01
-
-
Save notMasterpiece/0eed4510b41cdb51875cb950afbecc40 to your computer and use it in GitHub Desktop.
getChar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// event.type должен быть keypress | |
function getChar(event) { | |
if (event.which == null) { // IE | |
if (event.keyCode < 32) return null; // спец. символ | |
return String.fromCharCode(event.keyCode) | |
} | |
if (event.which != 0 && event.charCode != 0) { // все кроме IE | |
if (event.which < 32) return null; // спец. символ | |
return String.fromCharCode(event.which); // остальные | |
} | |
return null; // спец. символ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment