简体   繁体   中英

How to get unicode inputs on html/javascript?

You can easily get ASCII inputs using jQuery:

$('body').keypress(function(e){
    console.log('input: ',String.fromCharCode(e.keyCode));
});

Testing this snippet inputting special characters such as á é í ó ú doesn't give the expected input. How to get get the proper unicode input on HTML?

This works for me:

String.fromCharCode(225);

returns

"á"

Here is a solution that covers code units of UTF-16, although it says that you shouldn't have a problem, since your characters are all the "usual 2-byte ones":

developer.mozilla.org: String.fromCodePoint

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM