[英]jQuery Firefox handle behaviour on tab key
當我按下TAB鍵(典型的Google行為)時,我想在輸入字段中選擇一個建議條目。 我的問題是,當我按下TAB鍵時,Firefox會將焦點設置在打開應用程序的選項卡上,但我擔心的是焦點仍停留在輸入字段上。 我的代碼如下所示:
$("#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();
}
});
謝謝!
[編輯]解決了! 解決方案非常簡單:Firefox已對keydown
事件做出反應,因此我只需要在keydown
事件中添加相同的行為即可。
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.