在传统的网格布局 html table
(即,其中所有单元格恰好跨越一行和一列)?
我知道以下内容会将 nextCell
设置为被单击单元格紧邻右侧的单元格,因为它们是直接 sibling ,但我正在尝试检索紧挨着被单击单元格下方的单元格:
$('td').click(function () {
var nextCell = $(this).next('td');
});
我最好不使用任何类或 ID。
最佳答案
试试这个:
$("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();
});
关于javascript - jQuery:垂直获取下一个表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8840024/