按键事件时,Tab键在firefox中无效

时间:2014-02-18 07:28:04

标签: javascript jquery jquery-ui

在此代码的按键事件中,TAB键无法在FireFox中工作

   $('.Number').keypress(function (event) {
    if (!/\d/.test(String.fromCharCode(event.which))) {
        $('#error').attr('class', 'errorMessage');
        $('#error').text("Enter Only Numbers");
        return false;
    }
    else {
        $('#error').attr('class', ' display: none;');
        $('#error').text("");
        return true;
    }
});

1 个答案:

答案 0 :(得分:3)

$('.Number').keydown(function (event) {

    var keycode = event.which;   

    if (!/[\d\t\b]/.test(String.fromCharCode(event.which)) || event.shiftKey ) {
        $('#error').attr('class', 'errorMessage');
        $('#error').text("Enter Only Numbers");
        return false;
    } else {
        $('#error').attr('class', ' display: none;');
        $('#error').text("");
        return true;
    }
});

DEMO