Javascript 将insertRow()插入到特定的行id

Javascript 将insertRow()插入到特定的行id,javascript,jquery,dom,dynamic,innerhtml,Javascript,Jquery,Dom,Dynamic,Innerhtml,使用 如何指定新行位于所用的选定ID下,而不是硬编码索引或表的末尾?我有一个下拉列表,其中有不同的选项,可以选择将新行放在哪个行id下。下拉选项具有与相关行匹配的ID。谢谢这是我的表,我希望新行位于用户选择的父(父3、父4或父5)下 第3类 (父亲信息3,第3类) (父亲信息3,第3类) 第4类 (父亲信息4,第4类) (父亲信息4,第4类) id应该是索引,即:表。行类似于数组(它实际上不是数组,但行为类似于数组)。您可以使用id获取索引 <table id="shore_tab"

使用

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


第3类
(父亲信息3,第3类)
(父亲信息3,第3类)
第4类
(父亲信息4,第4类)
(父亲信息4,第4类)

id
应该是
索引
,即:
表。行
类似于数组(它实际上不是数组,但行为类似于数组)。

您可以使用id获取索引

 <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的行的索引,并将其(+1)传递给
insertRow
。var row=table.insertRow(0);这样地。但我不希望它的指定索引为0或-3。我需要将它放在所选行id之后。在该行的
索引中传递(不是
id
,因为没有这样的东西)。我更新了我的问题。我需要在父3、父4或父5下添加新行,具体取决于用户从下拉列表中选择的内容。@triplethreat77
id
将是用户选择的id,如
father3
等这似乎是一个完美的解决方案,但我无法让它工作。你能看看我以前的帖子吗?下拉列表的代码也在那里@triplethreat77您的
s有ID而没有值,请使用这些值获取所需行的行索引。我想我快疯了。我把确切的代码复制到了我的文档中…但它不起作用。要知道我的JSFIDLE是在Chrome中的,我的项目是在IE.Musa中的,这在Chrome中运行得很好,但不幸的是,我必须在IE中使用它。
 <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>
var row = table.insertRow(document.getElementById(id).rowIndex+1);//+1 to be inserted under