javascript - 如何通过按回车键关注同一列中的下一行输入

标签 javascript html

我正在保存纸张结果,我想像在 MS Excel 中那样通过按 Enter 键进行焦点快速保存它 在下一个底部单元格上

<tr>
    <td>1</td>
    <td>Muhammad Umar Abdur Rahman</td>
    <td>
        <input type="text" value="0" name="ReadingMarks257" onkeydown="Next(event)" class="input">
    </td>
    <td>
        <input type="text" value="0" name="WritingMarks257" onkeydown="Next(event)" class="input">
    </td>
    <td>
        <input type="text" value="0" name="PaperMarks257" onkeydown="Next(event)" class="input">
</tr>
<tr>
    <td>2</td>
    <td>Muhammad Abu Bakkar</td>
    <td>
        <input type="text" value="0" name="ReadingMarks258" onkeydown="Next(event)" class="input">
    </td>
    <td>
        <input type="text" value="0" name="WritingMarks258" onkeydown="Next(event)" class="input">
    </td>
    <td>
        <input type="text" value="0" name="PaperMarks258" onkeydown="Next(event)" class="input">
    </td>
</tr>

我已经尝试过

function Next(e) {
    if (e.which === 13) {
        var Element = $(this).closest('tr').next().find('.input');
        Element.focus();
    } else {
        $("#Msg").html('another Pressed');
    }
}

最佳答案

您可以使用nextElementSibling.focus():

function Next(e) { 
    if (e.which === 13) {
        e.target.nextElementSibling.focus();
    }
    else {
        $("#Msg").html('another Pressed');
    }
}

关于javascript - 如何通过按回车键关注同一列中的下一行输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59333919/

相关文章:

php - 在没有提交按钮的情况下调用php文件

html - CSS 下拉菜单在 IE 和 Firefox 中不起作用

javascript - 如何让我的结果在 javascript 中正确相加

javascript - 强制 Webpack 在 react-app bundle 中使用 ES6 语法

javascript - 适用于所有浏览器的 window.href

javascript - 单击它移动窗口的元素中心

html/css 编辑不会在不同的浏览器中更新

javascript - Angular 2 : why no empty element tags?

javascript - 在数组与对象中传播未定义

javascript - 在 html5 日期字段上启用复制/粘贴