在Firefox中使用JavaScript捕获Tab键

我使用以下内容限制用户只输入一些字符。 当我按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 = 97 && e.which <= 122) || e.which == 32 || e.which == 8 || e.which == 9)) { return false; } }); 

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

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

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