jQuery:垂直获取下一个表格单元格

Dev*_*rke 16 html javascript jquery

如何在传统的网格布局html中使用jQuery直接访问给定单元格下方的cell(td)(即,所有单元格恰好跨越一行和一列)?table

我知道以下内容将设置nextCell为单击单元格右侧的单元格,因为它们是直接兄弟,但我试图在单击的单元格下方检索单元格:

$('td').click(function () {
    var nextCell = $(this).next('td');
});
Run Code Online (Sandbox Code Playgroud)

我最好不要使用类或ID.

use*_*654 35

试试这个:

$("td").click(function(){
  // cache $(this);
  var $this = $(this);

  // First, get the index of the td.
  var cellIndex = $this.index();

  // next, get the cell in the next row that has
  // the same index.
  $this.closest('tr').next().children().eq(cellIndex).doSomething();
});
Run Code Online (Sandbox Code Playgroud)