数字键盘的keyCode值

数字键盘的keyCode值

本文介绍了数字键盘的keyCode值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

数字小键盘上的数字键码是否与键盘顶部的数字不同?

Do the numbers on a numeric keypad have a different keycode than the numbers at the top of a keyboard?

这是一些应该在keyup事件,但仅当密钥代码介于48和57之间时。以下是代码:

Here is some JavaScript that is supposed to run on the keyup event, but only if the keycode is between 48 and 57. Here is the code:

$('#rollNum').keyup(function(e) {
    if(e.keyCode >= 48 && e.keyCode <= 57) { //0-9 only
        var max = 15;
        var textLen = $(this).val().length;
        var textLeft = max - textLen;
        . . .

我的问题是此代码仅响应键盘顶部输入的数字而运行,但不会响应从数字键盘输入的数字而运行。

My problem is that this code only runs in response to the numbers entered at the top of the keyboard, but does not run in response to numbers entered from the numeric keypad.

我认为答案必须是数字键盘有不同的keyCode值,但我怎么知道它们是什么?

I'm thinking the answer must be that the numeric keypad has different keyCode values, but how do I find out what those are?

推荐答案

键码不同。键盘0-9是键码 96 105

The keycodes are different. Keypad 0-9 is Keycode 96 to 105

您的如果声明应该是:

if ((e.keyCode >= 48 && e.keyCode <= 57) || (e.keyCode >= 96 && e.keyCode <= 105)) {
    // 0-9 only
}

这是一个

这篇关于数字键盘的keyCode值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-25 16:12