【问题标题】:Updating n-th Row in Table with 'n-th child': on first row there is an error使用“第 n 个孩子”更新表中的第 n 行:在第一行出现错误
【发布时间】:2018-07-19 04:11:51
【问题描述】:

我的桌子是这样的,

<table>
  <thead>
    <tr>
      <th>Col 1</th>
      <th>Col 2</th>
      <th>Col 3</th>
    </tr>
  </thead>
  <tbody>
    <tr>
       <td>...</td>
       <td>...</td>
       <td>...</td>
    </tr>
    (etc)
  </tbody>
</table>

要使用我的自定义 HTML 更新第 i 行(var.rowIndex),使用 jQuery,我使用

$("table#tableID  tr:nth-child(" + (rowIndex) + ")").html(html);

“nth-child”是我在 StackOverflow 上某处找到的解决方案。

有效,但仅适用于非第一行。在 first 行,发生错误:同一行在第 1 行和 THEAD 标头中更新。因此,标头row 和 Row 1 具有相同的条目。

所有其他行更新都很好,它们更新正确。

【问题讨论】:

  • &lt;th&gt; 关闭不正确。将&lt;/th1&gt; 更改为&lt;/th&gt;
  • 抱歉,现在更正了 - 我只是在输入以显示 HTML 结构。现在在 OP 中已修复。

标签: javascript jquery html


【解决方案1】:

在选择器中指定 tbody

$("tableID tbody tr:nth-child(" + (rowIndex) + ")").html(html);

【讨论】:

  • 谢谢 - 实际上,由于我的原始帖子,这是一个小错字,它是 table#tableID。也许你也想在这里更正它。谢谢
猜你喜欢
  • 2017-03-11
  • 1970-01-01
  • 2012-09-04
  • 1970-01-01
  • 2014-04-24
  • 2016-03-05
  • 1970-01-01
  • 2016-07-08
  • 1970-01-01
相关资源
最近更新 更多