$(this).closest('tr').next() td:eq(7).focus();
这是什么错误?我是 jQuery 的新手。如何使用 tr
、td
和 table
索引进行聚焦?
$('.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/