如何使用 jQuery 将焦点移到下一个输入? [英] How do I move focus to next input with jQuery?

查看:32
本文介绍了如何使用 jQuery 将焦点移到下一个输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有 jQ​​uery 的自动完成插件,它运行良好.然而,在 IE 中,当用户在自动完成中选择一个项目时,焦点不会移动到下一个输入字段.它自然适用于 Firefox.该插件没有内置解决方案,但确实提供了选项".有没有办法强制它移动到下一个输入字段?

I am using the autocomplete plugin with jQuery and it is working fine. However, in IE, when the user selects an item in the autocomplete, the focus does not then move to the next input field. Naturally it works in Firefox. The plugin doesn't have a built-in solution but does provide for "options". Is there a way I can force it to move to the next input field?

推荐答案

你可以这样做:

$("input").change(function() {
  var inputs = $(this).closest('form').find(':input');
  inputs.eq( inputs.index(this)+ 1 ).focus();
});

此处发布的其他答案可能对您不起作用,因为它们取决于下一个输入是下一个同级元素,而通常情况并非如此.这种方法进入表单并搜索下一个输入类型元素.

The other answers posted here may not work for you since they depend on the next input being the very next sibling element, which often isn't the case. This approach goes up to the form and searches for the next input type element.

这篇关于如何使用 jQuery 将焦点移到下一个输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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