jQuery如何使Enter(Return)作为Tab键通过输入文本字段,但最终触发提交按钮

问题描述:

我已经阻止了Enter(返回)键,实际上它在Tab键中进行了转换。所以当在输入文本字段内按压时,它作为Tab键。这是好的,但是我需要它在最后一个字段中按下时触发提交按钮,下面是Enter键突变的代码:

I've blocked Enter (return) key, actually, transformed it in Tab key. So when pressed inside input text fields it acts as Tab key. This is good, but I need it to trigger the submit button when pressed in the last field, below is the code for the Enter key mutation:

            $('input').keydown(function(event) {
                if(event.which == 13) {
                    event.preventDefault();
                    $(this).nextAll('input:first').focus();
                }
            });

表单代码是输入类型=文本而在结尾的一个按钮type =submit

其实代码是这个,从 jquery:在特定部分中输入Tab触发器。但我不知道今天昨天工作的原因是不起作用的:

And the form code is a sequence of input type="text" and a button type="submit" at the end Actually the code is this one, taken from jquery: Enter to Tab trigger in specific parts. But I don't know why it was working yesterday today is not working:

$(':text').keydown(function(e) {
    if(e.keyCode == 13 && $(this).attr('type') != 'submit') {
        e.preventDefault();
        $(this).nextAll('input:first').focus();
    }
});


如果你最后输入最后一个类只需将您的代码修改为

If you give your last input the class of last then simply modify your code to something like

$('input').keydown(function(event) {
            if(!$(this).hasClass("last")){
                if(event.which == 13) {
                    event.preventDefault();
                    $(this).nextAll('input:first').focus();
                }
            }
        });