javascript - 获取表的 eq( ) 和第 n 个 child

标签 javascript jquery html

我有下表:

<table id="some-table">
<thead>
  <tr>
    <th>Name</th>
    <th>Type</th>
    <th>UI Status</th>
    <th>Engine Status</th>
 </tr>
</thead>
<tbody>
<tr>
    <th>A</th>
    <th>1</th>
    <th></th>
    <th></th>
</tr>
<tr>
    <th>B</th>
    <th>2</th>
    <th></th>
    <th></th>
 </tr>
</tbody>
</table>

我想将 UI 状态插入索引处的表中。

$(#'some-table tbody tr').eq(0) 会得到我想要的行,但我如何得到第 3 个 th tr 这样我就可以更新 UI 状态。

感谢任何帮助。

谢谢。

最佳答案

您可以链式调用以在元素中查找子元素:

$(#'some-table tbody tr').eq(0).find('th').eq(2)

你也可以在选择器中使用:eq伪类:

$(#'some-table tbody tr:eq(0) th:eq(2)')

关于javascript - 获取表的 eq( ) 和第 n 个 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30247871/

相关文章:

javascript - 'Form' 未定义 react/jsx-no-undef

javascript - Jquery animate 在控制台中有效,但在脚本中无效

html - 显示 flex 未按预期工作

javascript - 错误typeerror : _co. onclk不是一个函数

javascript - GO - html 文件无法加载外部 js 文件

javascript - 我无法移动节点,力图不适用于 3.js

javascript - Angularjs 分割数组

javascript - 存储越来越多的数字以继续刷新?

javascript - 在元素上切换 CKEditor

javascript - 在 Vanilla JS 中滚动到下一部分并返回到顶部而无需 ID - 无 JQUERY