How to convert keycode to character using javascript [duplicate]

帅比萌擦擦* 提交于 2019-11-28 16:56:50

问题


This question already has an answer here:

  • Get Character value from KeyCode in JavaScript… then trim 10 answers

How to convert keycode to character using javascript

var key_code = 65;

result should be

character = "a";

回答1:


String.fromCharCode() is what you want:

The fromCharCode() method converts Unicode values to characters.

Syntax

String.fromCharCode(n1, n2, ..., nX)



回答2:


As seen here:

String.fromCharCode((96 <= key && key <= 105) ? key-48 : key)


来源:https://stackoverflow.com/questions/3977792/how-to-convert-keycode-to-character-using-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!