简体   繁体   English

jQuery Firefox处理选项卡键上的行为

[英]jQuery Firefox handle behaviour on tab key

I would like to select an suggestion entry in my input field when I press the TAB key (typical Google behaviour). 当我按下TAB键(典型的Google行为)时,我想在输入字段中选择一个建议条目。 My Problem is that when I press the TAB key, Firefox sets the focus on the tab in which my application is open, but my concern is that the focus stays on my input field. 我的问题是,当我按下TAB键时,Firefox会将焦点设置在打开应用程序的选项卡上,但我担心的是焦点仍停留在输入字段上。 My code looks something like: 我的代码如下所示:

$("#search-input").keyup(function (event) {
    switch (event.keyCode) {
        case 9:
            {   
                // tab key is pressed
                event.preventDefault();
                foo();
                bar();
                //set focus back to the input (dont works)
                $("#search-input").focus(); 
                break;
            }
        default:
            baz();
    }
});    

thanks! 谢谢!

[EDIT] Solved! [编辑]解决了! The solution is very easy: Firefox reacts already on keydown event so I needed just to put the same behaviour in the keydown event. 解决方案非常简单:Firefox已对keydown事件做出反应,因此我只需要在keydown事件中添加相同的行为即可。

Firefox reacts already on keydown event so I needed just to put the same behaviour in the keydown event. Firefox已经对keydown事件做出了反应,因此我只需要在keydown事件中添加相同的行为即可。

$("#search-input").keydown(function (event) {
    switch (event.keyCode) {
        case 9:
            {   
                // tab key is pressed
                event.preventDefault();
                foo();
                bar();
                //set focus back to the input (dont works)
                $("#search-input").focus(); 
                break;
            }
        default:
            baz();
    }
}); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM