[英]insertRow() to specific row id
使用
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"> </td>
</tr>
<tr class="row_blue_bold son3">
<td class="cell_20 cell_no_bkg"> </td>
<td class="cell_190">(information for father3, category 3)</td>
<td class="cell_50"> </td>
</tr>
<tr class="row_blue_bold son3">
<td class="cell_20 cell_no_bkg"> </td>
<td class="cell_190">(information for father3, category 3)</td>
<td class="cell_50"> </td>
</tr>
<tr class="row_blue_bold father" id="father4">
<td colspan="2" class="father_header">Category 4</td>
<td class="cell_50"> </td>
</tr>
<tr class="row_blue_bold son4">
<td class="cell_20 cell_no_bkg"> </td>
<td class="cell_190">(information for father4, category 4)</td>
<td class="cell_50"> </td>
</tr>
<tr class="row_blue_bold son4">
<td class="cell_20 cell_no_bkg"> </td>
<td class="cell_190">(information for father4, category 4)</td>
<td class="cell_50"> </td>
</tr>
</table>
您可以使用ID獲取索引
var row = table.insertRow(document.getElementById(id).rowIndex+1);//+1 to be inserted under
id
應該是index
,即: table.rows
就像一個Array(它實際上不是一個Array,但是表現得像一個)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.