在javascript中模拟tab键功能 [英] simulate the tab key function in javascript

查看:159
本文介绍了在javascript中模拟tab键功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的表格中有很多条目。一旦我在当前文本框中输入值,我想将焦点更改为下一个文本框。并希望将此过程继续到最后一个字段。我的问题是,一旦我在文本框中输入值,是否可以通过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 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();
       }
    }
});

这篇关于在javascript中模拟tab键功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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