我正在使用以下代码来检测正在按下的键:
$(document).keyup(function(event) { // the event variable contains the key pressed
if (event.which == x+65) {
alert(numToChar(x));
}
});
“B”是键码66;然而,当我按下“b”时它会触发,并警告66,这是大写B键码。小'b'应警告“98”
我在firefox和chrome中尝试了这个。
答案 0 :(得分:0)
如果您需要区分大小写的密钥代码,请将事件更改为按键。
$(document).keypress(function(event) { // the event variable contains the key pressed
if (event.which == x+65) {
alert(numToChar(x));
}
});