用javascript删除当前行,添加行(示例代码)
<script>
function del(obj)
{
obj.parentNode.parentNode.removeNode(true);
}
</script>
<body>
<table>
<tr>
<td>单元格1</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
<tr>
<td>单元格2</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
<tr>
<td>单元格3</td>
<td><input type=button value="delete this row" onclick="del(this)"></td>
</tr>
</table>
</body>
<script>
function uf_test(){
//得到table对象
var tbTable = document.getElementById("tb_test");
//插入一行
var trT = tbTable.insertRow();
//得到上一行的td数
var nRows = tbTable.rows[0].cells.length;
//按上一行的td数循环进行插入td
for(var i = 0; i < nRows ; i++){
//创建td对象
var tdT = document.createElement("TD");
//给td对象赋值
//tdT.innerHTML="sfsdf";
tdT.innerText="sfsdf";
//把td添加到tr中
trT.appendChild(tdT);
}
}
</script>
<table id="tb_test" border="1">
<tr>
<td><input type="text"></td>
</tr>
</table>
<input type="button" onclick="uf_test();" value="增加一行">