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

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

问题描述

我使用jQuery的自动完成插件,它是工作的罚款。然而,在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天全站免登陆