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

标签 javascript jquery html

在传统的网格布局 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/

相关文章:

javascript - 使用 jQuery 使用 CSS 为文本着色

javascript - 了解 Javascript 链接模式

javascript - 加载页面问题上的引导模式

javascript - 链接转到最后滚动位置而不是 anchor

jquery - 设置 div 的类动态地关注其父级中的 div 位置

html - 无法对齐图像旁边的文本

javascript - WinSCP 刷新 PHP 代码库?如何使用 XMLHttpRequest 发送文件后刷新服务器

javascript - ClojureScript 中的向量到元素?

javascript - 如何创建一个自动完成的组合框?

javascript - 按钮不改变背景和文本的颜色