如何将一个字符转换成相应的键码?
例如:
a
到65
b
到66
c
到67
d
到68
最佳答案
您可以使用 charCodeAt
实现这一目标的功能。
工作示例:
function showKeyCode () {
var character = document.getElementById("character").value.substring(0, 1);
var code = document.getElementById("character").value.charCodeAt(0);
var msg = "The Key Code for the \"" + character + "\" character is " + code + ".";
alert(msg);
}
<input type="text" id="character" size="15">
<input type="button" value="Show Key Code" onclick="showKeyCode();">
关于javascript - 如何将字符转换为其键码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1430989/