Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 按enter键移动到表中的下一个单元格_Javascript_Jquery - Fatal编程技术网

Javascript 按enter键移动到表中的下一个单元格

Javascript 按enter键移动到表中的下一个单元格,javascript,jquery,Javascript,Jquery,我正在尝试创建一个表单,如果您在序列列上按enter键,下面的单元格将被选中。有人能为这个任务解决正确的jquery公式吗 我正在努力 $('.serial').keypress(function(e) { console.log(this); if (e.which == 13) { $(this).nextAll('#serial').first().focus(); e.preventDefault(); } }); 如果在任何输

我正在尝试创建一个表单,如果您在序列列上按enter键,下面的单元格将被选中。有人能为这个任务解决正确的jquery公式吗

我正在努力

$('.serial').keypress(function(e) {
    console.log(this);
    if (e.which == 13) {
        $(this).nextAll('#serial').first().focus();
        e.preventDefault();
    }
});


如果在任何输入中按enter键时要移动到下面的单元格,请使用以下命令:

$('table input').keypress(function(e) {
    if (e.keyCode == 13) {
        var $this = $(this),
            index = $this.closest('td').index();

        $this.closest('tr').next().find('td').eq(index).find('input').focus();
        e.preventDefault();
    }
});

这是你的小把戏:

下一个dom插件就是为此编写的。免责声明:是我写的


“#串行”!=”。串行'
是否可以进行循环?
$('table input').keypress(function(e) {
    if (e.keyCode == 13) {
        var $this = $(this),
            index = $this.closest('td').index();

        $this.closest('tr').next().find('td').eq(index).find('input').focus();
        e.preventDefault();
    }
});
$('.serial').keypress(function(e) {
    if (e.which == 13) {
        $(this).nextInDOM('.serial').focus();
    }
});