<html>
<script language="javascript">
var rowid=1;
function $(id){
return document.getElementById(id);
}
function addRow(){
var _tab=$("test");
var _row=_tab.insertRow();
rowid+=1;
var _col1=_row.insertCell();
_col1.innerText=rowid;
_col1.align= "center ";
var _col2=_row.insertCell(1);
_col2.innerHTML= " <input type= 'text'> ";
_col2.align= "center ";
var _col3=_row.insertCell(2);
_col3.innerHTML= " <input type= 'text'> ";
_col3.align= "center ";
var _col4=_row.insertCell(3);
_col4.innerHTML= " <input type= 'text'> ";
_col4.align= "center ";
}
</script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title> 增加行 </title>
</head>
<body>
<table>
<tr>
<td align="center" valign="top">
<table width="200" border="1 " align="center ">
<tr>
<td><input type="submit" name="addBtnss" value=" add " οnclick="addRow();"></td>
</tr>
<tr>
<td> <input type="submit " name="addBtn" value="delete "> </td>
</tr>
</table>
</td>
<td> <table id="test" border="1">
<tr>
<td> </td> <td align="center"> ID </td> <td align="center"> Name </td> <td align="center"> Desc </td>
</tr>
<tr>
<td align="center" width="50"> 1 </td>
<td> <input type="text" name="id" id="testId "> </td>
<td> <input type="text" name="name " id="testName"> </td>
<td> <input type="text" name="desc " id="testDesc"> </td>
</tr>
</table> </td>
</tr>
</table>
</body>
</html>
引入:javascript操作table(insertRow,deleteRow,insertCell,deleteCell方法详解)_mengzhengjie的博客-CSDN博客