开发者

Capturing the tab key using JavaScript in Firefox

开发者 https://www.devze.com 2023-02-06 20:31 出处:网络
I use the follo开发者_运维知识库wing 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.

I use the follo开发者_运维知识库wing 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 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?


Perhaps if you start with something like:

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

精彩评论

暂无评论...
验证码 换一张
取 消