如何获取html/javascript上的unicode输入? [英] How to get unicode inputs on html/javascript?

查看:118
本文介绍了如何获取html/javascript上的unicode输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可以使用jQuery轻松获得ASCII输入:

You can easily get ASCII inputs using jQuery:

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

测试此代码段以输入áéíú之类的特殊字符不会提供预期的输入.如何获得正确的HTML Unicode输入?

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

推荐答案

这对我有用:

String.fromCharCode(225);

返回

"á"

这是一个涵盖UTF-16代码单元的解决方案,尽管它说您应该没有问题,因为您的字符都是通常的2字节字符":

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

这篇关于如何获取html/javascript上的unicode输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆