简体   繁体   中英

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). 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. 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 reacts already on keydown event so I needed just to put the same behaviour in the keydown event.

$("#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();
    }
}); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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