javascript将字符转换为密钥代码

时间:2012-11-06 02:27:30

标签: javascript

  

可能重复:
  Convert character to ASCII code in Javascript

如何将任何字符转换为密钥代码,如

m    77
n    78
o    79
p    80
q    81
r    82
s    83
t    84
u    85
v    86

1 个答案:

答案 0 :(得分:1)

var alphabet = 'abcdefghijklmnopqrstuvwxyz'.split(''),
    len = alphabet.length,
    i;

for (i = 0; i < len; ++i) {
    console.log(alphabet[i], alphabet[i].charCodeAt(0) - 32);
}

http://jsfiddle.net/zerkms/n2ZFa/