javascript - 焦点使用 Jquery <tr> <td>

标签 javascript jquery html

$(this).closest('tr').next() td:eq(7).focus();

这是什么错误?我是 jQuery 的新手。如何使用 trtdtable 索引进行聚焦?

$('.gridfield').keypress(function(e) {
    console.log(this);
    if (e.which == 13) {    
        var row_index = $(this).parent().index();    
        $(this).closest('tr').next() td:eq(row_index).focus();     
        e.preventDefault();
    }
});

最佳答案

语法不太正确。您可以使用以下任一方法:

$(this).closest('tr').next().find('td').eq(row_index).focus();     

或者这个:

$(this).closest('tr').next().find('td:eq(' + row_index + ')').focus();     

它们在逻辑上是相同的。

Each cell contains input field

在那种情况下使用其中之一:

$(this).closest('tr').next().find('td').eq(row_index).find('input').focus(); 
$(this).closest('tr').next().find('td:eq(' + row_index + ') input').focus(); 

关于javascript - 焦点使用 Jquery <tr> <td>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36736650/

相关文章:

javascript - IE过滤器抗锯齿问题

javascript - 从嵌入页面中运行的脚本向容器页面中的脚本发送数据

javascript - 为什么 Highcharts 中的标记点与 y 轴不对齐?

HTML 简单表单文本输入样式

javascript - 我们可以在用户点击事件上将输入隐藏变量传递到新页面吗?

javascript - Bootstrap 数据表复选框更改类

javascript - 使用 jQuery 显示或隐藏 div 元素

javascript - 克隆后无法从选择框中选择选项

html - 我的背景消失了

javascript - Ionic - 后退按钮关闭键盘但输入仍然聚焦