Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用javascript将键码转换为字符
var key_code = 65;
结果应该是
character = "a";
String.fromCharCode()是你想要的:
String.fromCharCode()
fromCharCode() 方法将 Unicode 值转换为字符。 句法 String.fromCharCode(n1, n2, ..., nX)
fromCharCode() 方法将 Unicode 值转换为字符。
String.fromCharCode(n1, n2, ..., nX)
如此处所示:
String.fromCharCode((96 <= key && key <= 105) ? key-48 : key)