Jquery 在 Enter 键上选择 NEXT 文本字段 [英] Jquery select NEXT text field on Enter Key Press

查看:33
本文介绍了Jquery 在 Enter 键上选择 NEXT 文本字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 jquery 创建了一个页面,加载时它会自动选择第一个文本字段.我希望它在按下 ENTER 键时移动到下一个字段.

I have made a page using jquery, and on load it selects the first text field automatically. I want it to then move to the next field when the ENTER key is pressed.

$('.barcodeField input').bind('keyup', function(event) {
    if(event.keyCode==13){
       $("this + input").focus();     
    }
});

我在网上找不到任何有效的东西.我已经搜索了论坛.

I can't find anything that works on the net. And I've scoured the forums.

推荐答案

我创建了一个小函数,可以满足你的需求.这是我使用的版本,因此您可能需要更改类名,但您应该明白了.

I've created a little function which can do what you need. This is the version I use so you may need to change the class names but you should get the idea.

<script type="text/javascript">
$(document).ready(function(){
$(".vertical").keypress(function(event) {
        if(event.keyCode == 13) { 
        textboxes = $("input.vertical");
        debugger;
        currentBoxNumber = textboxes.index(this);
        if (textboxes[currentBoxNumber + 1] != null) {
            nextBox = textboxes[currentBoxNumber + 1]
            nextBox.focus();
            nextBox.select();
            event.preventDefault();
            return false 
            }
        }
    });
})
</script>

所以基本上:-

  • 获取所有匹配 .vertical 的输入字段
  • 查找当前文本框
  • 寻找下一个
  • 将焦点放在那个上

这篇关于Jquery 在 Enter 键上选择 NEXT 文本字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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