事件keyCode的数值不同 [英] Event keyCode different for Numeric value

查看:109
本文介绍了事件keyCode的数值不同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆