事件keyCode的数值不同 [英] Event keyCode different for Numeric value
问题描述
jQuery代码
only_float
是文本框类名称.
$(".only_float").live("down",function(event){
console.log(event.keyCode);
});
当我在下面提到的图像上按数字键按1时,它将显示 49 作为keyCode.
When I press 1 from Numeric key on following mentioned image then it will Display 49 for keyCode.
当我在下面提到的图像上按数字键中的1时,它将显示 97 作为keyCode.
When I press 1 from Numeric key on following mentioned image then it will Display 97 for keyCode..
我的问题是为什么相同数字值的键码不同?
推荐答案
在JavaScript中触发键盘事件时,event.keyCode
包含按下的键的键代码.碰巧,数字小键盘和标准位置数字有两个不同的常数.
When a keyboard event is triggered in JavaScript, the event.keyCode
contains the keycode of the key that was pressed. It just so happens that there are two different constants for the numerical keypad and the standard location numbers.
从 MDN参考,定义了以下常量:
DOM_VK_1 = 0x31 (49)
和 DOM_VK_NUMPAD1 = 0x61 (97)
因此,keyCode
可能完全不同,具体取决于按下的是物理键,是常规的1
还是数字小键盘1
.
Thus, the keyCode
may very well be different, depending on which physical key was pressed, whether the regular 1
or the numeric keypad 1
.
这篇关于事件keyCode的数值不同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!