在回车键上移动到表中的下一个单元格

On enter key move to next cell down in a table

本文关键字:下一个 单元格 回车 移动      更新时间:2023-09-26

我正在尝试创建一个表单,如果您在串行列上按回车键,下面的单元格将被选中。有人可以解决此任务的正确jquery公式吗?

我正在尝试

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

http://jsfiddle.net/tYFcH/4/

假设您想在任何输入中按回车键时移动到下面的单元格,请使用以下命令

$('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();
    }
});

这是你的小提琴:http://jsfiddle.net/tYFcH/13/

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

http://jsfiddle.net/tYFcH/6/

next-in-dom 插件就是为此目的而编写的。免责声明:我写的

http://techfoobar.com/jquery-next-in-dom/

$('.serial').keypress(function(e) {
    if (e.which == 13) {
        $(this).nextInDOM('.serial').focus();
    }
});