使用 Jquery 按键后重点关注下一个输入
注意:我的页面只有文本框。没有别的了。 (没有别的=>没有其他输入类型)
$(":input[type='text']").keyup(function(event){
if(valid)
{
// take a focus to next input element, which is again a text type.
}
});
如何在按键后将焦点跳到下一个输入元素。
Sarfraz 答案之后:-
<div>
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" > // sarfraj -- here it crash Please check below for error.
</div>
<div>
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
</div>
来自 firebug 问题是
$(this).next("[type=\"text\"]")[0] is undefined
[Break On This Error] $(this).next('[type="text"]')[0].focus();
Note: My page has just textboxes. Nothing else. (nothing else => no other input types)
$(":input[type='text']").keyup(function(event){
if(valid)
{
// take a focus to next input element, which is again a text type.
}
});
How can i jump the focus to next input element after key up.
After Sarfraz Answer:-
<div>
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" > // sarfraj -- here it crash Please check below for error.
</div>
<div>
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
<input type="text" maxlength="1" size="1" >
</div>
From firebug issue is
$(this).next("[type=\"text\"]")[0] is undefined
[Break On This Error] $(this).next('[type="text"]')[0].focus();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
更新:
以下是您应该如何修改代码:
将
next()
与focus
结合使用:因此,您的代码应如下所示:
Update:
Here is how you should modify your code:
Use the
next()
withfocus
:So here is how your code should look like:
html
tabindex
属性用于定义顺序如果按 Tab 键,您将在输入元素之间移动。我将从设置这个开始。因此,然后设置选项卡索引(以扩展您的示例):
基本上获取当前元素的
tabindex
,添加 1,然后获取具有该选项卡索引的元素。The html
tabindex
property is used to define the order by which you move through the input elements if you hit tab. I would start by setting this.So set the tab indexes then (to expand on your example):
Basically get the
tabindex
of the current element, add 1, and get the element with that tab index.