日期:2014-05-16 浏览次数:20400 次
<html> <body> <table id = "tab1" border = 1> <tr> <td><input type="text" /></td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> </tr> <tr> <td><input type="text" /></td> <td>b</td> <td>c</td> <td>d</td> <td>e</td> </tr> </table> <button onClick="addRow()">添加行</button> <button onClick="deleteRow()">删除行</button> <script type="text/javascript"> function addRow() { var theTable = document.getElementById("tab1"); newrow = theTable.lastChild.cloneNode(true); //复制最后一行 theTable.appendChild(newrow); //插入 } function deleteRow() { var theTable = document.getElementById("tab1"); var totalRow = theTable.childNodes.length; if (navigator.userAgent.indexOf("MSIE") == -1 ) //如果不是ie 总行数减1 totalColume = totalRow-1; if (totalColume > 1 ) { // alert(totalRowume); theTable.removeChild(theTable.lastChild); } } </script> </html>