JavaScript的键码

时间:2019-02-25 18:35:46

标签: javascript

这是关键代码列表:https://www.cambiaresearch.com/articles/15/javascript-char-codes-key-codes

此处“ a”的键码为65,而“ b”的键码为66

但是这个简单的测试给出了不同的结果:

<textarea type="text" id="txt"></textarea>

js:

const input = document.querySelector('#txt');
input.addEventListener('keypress', event => {

    console.log( event.keyCode ) ;

});

“ a”的键代码返回97,而“ b”-98

我误会了什么?

2 个答案:

答案 0 :(得分:2)

小写字母“ a”为97,大写字母“ A”为65。 enter image description here

答案 1 :(得分:2)

if ($data['eventType'] -eq '59') { # do some } else { # do other } 的键码为 97 a的键码为 65 。对于小写和大写字母,它们是不同的。您可以在代码段中尝试一下。

A
const input = document.querySelector('#txt');
input.addEventListener('keypress', event => {

    console.log( event.keyCode ) ;

});