在Firefox中使用JavaScript捕获Tab键

时间:2022-04-29 10:04:25

I use the following to restricts user to enter only some characters. When I press tab, the cursor does not point to next control (in Mozilla). But it works fine in IE.

我使用以下内容限制用户只输入一些字符。当我按Tab键时,光标不指向下一个控件(在Mozilla中)。但它在IE中运行良好。

// Restricts user to enter characters other than a to z, A to Z and white space( )
// Rauf K. 06.11.2010
$("input:text.characters_only").keypress(function(e) {
if (!((e.which >= 65 && e.which <= 90) || (e.which >= 97 && e.which <= 122) || e.which == 32 || e.which == 8 || e.which == 9)) {
        return false;
    }
});

2 个解决方案

#1


8  

I would recommend trying e.keyCode instead of e.which. Here is a SO link that describes a good method of getting the key strike into a single variable regardless: jQuery Event Keypress: Which key was pressed?

我建议尝试使用e.keyCode而不是e.which。这是一个SO链接,它描述了一个将键敲击变为单个变量的好方法,无论如何:jQuery Event Keypress:按下了哪个键?

#2


5  

Perhaps if you start with something like:

也许如果你从以下内容开始:

if (e.keyCode === 9) { // TAB
    return true;
}

#1


8  

I would recommend trying e.keyCode instead of e.which. Here is a SO link that describes a good method of getting the key strike into a single variable regardless: jQuery Event Keypress: Which key was pressed?

我建议尝试使用e.keyCode而不是e.which。这是一个SO链接,它描述了一个将键敲击变为单个变量的好方法,无论如何:jQuery Event Keypress:按下了哪个键?

#2


5  

Perhaps if you start with something like:

也许如果你从以下内容开始:

if (e.keyCode === 9) { // TAB
    return true;
}