gpt4 book ai didi

javascript - insertRow() 到特定行 id

转载 作者:行者123 更新时间:2023-12-02 19:04:24 25 4
gpt4 key购买 nike

使用

var row = table.insertRow(id);

如何指定新行位于所使用的所选 ID 下,而不是硬编码索引或表末尾?我有一个下拉菜单,其中有不同的选项可以选择将新行放置在哪个行 ID 下。下拉选项具有与相关行匹配的 ID。谢谢。这是我的表格,我希望新行位于用户选择的父亲(father3、father4 或father5)下

 <table id="shore_tab" border="1">
<tr class="row_blue_bold father" id="father3">
<td colspan="2" class="father_header">Category 3</td>
<td class="cell_50">&nbsp;</td>
</tr>
<tr class="row_blue_bold son3">
<td class="cell_20 cell_no_bkg">&nbsp;</td>
<td class="cell_190">(information for father3, category 3)</td>
<td class="cell_50">&nbsp;</td>
</tr>
<tr class="row_blue_bold son3">
<td class="cell_20 cell_no_bkg">&nbsp;</td>
<td class="cell_190">(information for father3, category 3)</td>
<td class="cell_50">&nbsp;</td>
</tr>
<tr class="row_blue_bold father" id="father4">
<td colspan="2" class="father_header">Category 4</td>
<td class="cell_50">&nbsp;</td>
</tr>
<tr class="row_blue_bold son4">
<td class="cell_20 cell_no_bkg">&nbsp;</td>
<td class="cell_190">(information for father4, category 4)</td>
<td class="cell_50">&nbsp;</td>
</tr>
<tr class="row_blue_bold son4">
<td class="cell_20 cell_no_bkg">&nbsp;</td>
<td class="cell_190">(information for father4, category 4)</td>
<td class="cell_50">&nbsp;</td>
</tr>
</table>

最佳答案

可以使用id来获取索引

var row = table.insertRow(document.getElementById(id).rowIndex+1);//+1 to be inserted under

关于javascript - insertRow() 到特定行 id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14464718/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com