按Tab键后jQuery设置焦点按 [英] jQuery Set Focus After Tab Key Press
本文介绍了按Tab键后jQuery设置焦点按的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
按TAB键后,我正在尝试将焦点设置到特定的文本框。页面上只有一个文本框。看起来很简单。
I'm trying to set the focus to a particular text box after pressing the TAB key. There is only one text box on the page. It seems pretty simple.
$("#status").keydown(function (e) {
if (e.which == 9) {
$("#statuses").html(this.value);
this.value = "";
$("#status").focus();
}
});
这是我的jsFiddle示例:
Here is my jsFiddle example:
如果我为ENTER按钮编码它可以正常工作,但对于TAB,它只是转到URL栏。
If I code it for the ENTER button it works fine, but for TAB it just goes to the URL bar.
推荐答案
你需要停止默认行为,试试这个
You need to stop the default behavior, try this
$("#status").keydown(function (e) {
if (e.which == 9) {
$("#statuses").html(this.value);
this.value = "";
$("#status").focus();
e.preventDefault();
}
});
小提琴:
http://jsfiddle.net/7Rfqa/1/
这篇关于按Tab键后jQuery设置焦点按的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文