admin管理员组文章数量:1391960
I have two textboxes and when TAB is pressed from one textbox it goes to another place instead of to the next textbox.
My code is:
$(function () {
$("input[id$=txt1]").bind('keydown',
function (e) {
if (e.which == 9) {
// alert("hello");
$("input[id$=txt2]").focus();
}
}
);
});
When I press tab for txt1 it should go to txt2 but it doesn't.
Any help?
I have two textboxes and when TAB is pressed from one textbox it goes to another place instead of to the next textbox.
My code is:
$(function () {
$("input[id$=txt1]").bind('keydown',
function (e) {
if (e.which == 9) {
// alert("hello");
$("input[id$=txt2]").focus();
}
}
);
});
When I press tab for txt1 it should go to txt2 but it doesn't.
Any help?
Share Improve this question edited Apr 5, 2012 at 18:53 demBones 1551 silver badge5 bronze badges asked Jan 5, 2012 at 6:04 G.S BhangalG.S Bhangal 3,3004 gold badges26 silver badges48 bronze badges2 Answers
Reset to default 6You don't have to do any code here. You just have to assign tab indexes in a proper order.
For example:
<input type="text" value="a" tabindex="1" />
<input type="text" value="c" tabindex="3" />
<input type="text" value="b" tabindex="2" />
If you set a focus to "a", then push TAB, focus will move to "c", and then to "b".
See demo here: http://jsbin./epacop/2
Just use preventDefault and it will work
$("#txt1").bind('keydown',
function (e) {
if (e.which == 9) {
$("#txt2").focus();
e.preventDefault()
}
}
);
BTW, its much better to use direct selectors with ids (#txt2 instead of input[id$=txt2]).
本文标签: javascriptOn click of TAB the focus should be on the next textboxStack Overflow
版权声明:本文标题:javascript - On click of TAB the focus should be on the next textbox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744720055a2621641.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论