最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - Capturing the tab key using JavaScript in Firefox - Stack Overflow

programmeradmin0浏览0评论

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.

// 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;
    }
});

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.

// 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;
    }
});
Share Improve this question edited Jan 25, 2011 at 12:17 Marcel Korpel 21.8k6 gold badges62 silver badges80 bronze badges asked Jan 25, 2011 at 12:01 RaufRauf 12.9k22 gold badges79 silver badges128 bronze badges 0
Add a ment  | 

2 Answers 2

Reset to default 8

I would remend 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?

Perhaps if you start with something like:

if (e.keyCode === 9) { // TAB
    return true;
}
发布评论

评论列表(0)

  1. 暂无评论