当前输入有值时,如何前进到下一个表格输入? [英] How to advance to the next form input when the current input has a value?

查看:90
本文介绍了当前输入有值时,如何前进到下一个表格输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格中有很多条目。一旦我在当前文本框中输入值,我想将焦点更改为下一个文本框。并希望将此过程继续到最后一个字段。我的问题是,当我在文本框中输入值时,是否可以模拟通过javascript编码按Tab键时发生的情况。

I am having a form with lots of entries. I would like to change my focus to the next textbox, once i entered the value in the current textbox. and want to continue this process upto the last field. My question is, is it possible to simulate what happens when pressing the tab key through javascript coding once i enter the value in the text box.

无需按Tab键键盘,我想通过javascript带来相同的功能。这可能吗?

Without pressing the tab key in keyboard, i would like to bring the same functionality through javascript. Is this possible ?

推荐答案

你只需要将焦点放在下一个输入字段上(通过在该输入上调用focus()方法) element),例如,如果你使用jQuery,这个代码会在按下enter时模拟tab键:

you just need to give focus to the next input field (by invoking focus()method on that input element), for example if you're using jQuery this code will simulate the tab key when enter is pressed:

var inputs = $(':input').keypress(function(e){ 
    if (e.which == 13) {
       e.preventDefault();
       var nextInput = inputs.get(inputs.index(this) + 1);
       if (nextInput) {
          nextInput.focus();
       }
    }
});

这篇关于当前输入有值时,如何前进到下一个表格输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆