简单的appendChild示例

mac2022-06-30  24

<html> <head> <script type="text/javascript"> function alertRowIndex() { alert(document.getElementById("tr4").parentNode.innerHTML); alert(document.getElementById("tr4").rowIndex); } function addRow() { var tr3=document.getElementById("tr3"); var tr4=tr3.cloneNode(true); tr4.id="tr4"; tr3.parentNode.appendChild(tr4); } </script> </head> <body> <table border="1"> <tr id="tr1"> <th>Firstname</th> <th>Lastname</th> </tr> <tr id="tr2"> <td>Peter</td> <td>Griffin</td> </tr> <tr id="tr3"> <td>Peter</td> <td>Griffin</td> </tr> </table> <br /> <input type="button" οnclick="alertRowIndex()" value="Alert row index" /> <input type="button" οnclick="addRow()" value="Add new row" /> </body> </html>

  

转载于:https://www.cnblogs.com/wonder223/archive/2012/11/23/2783810.html

相关资源:JS中appendChild追加子节点无效的解决方法
最新回复(0)