<script language=javascript>
function delrow(cellobj)
{
cellobj.parentNode.parentNode.deleteRow(cellobj.parentNode.rowIndex);
}function addrow()
{
var t=document.getElementById('table1'); //得到table引用
t.insertRow(t.rows.length); //插入空白行 var tcell;
tcell=t.rows[t.rows.length-1].insertCell(0) //插入单元格,并获取引用
tcell.appendChild(document.createTextNode('xxx')); //增加文本
tcell=t.rows[t.rows.length-1].insertCell(1)
tcell.appendChild(document.createTextNode('这是插入行'));
}
</script><table border=1 id="table1">
<tr><td>111</td> <td onclick="delrow(this)">点击删除此行</td>
<tr><td>222</td> <td onclick="delrow(this)">点击删除此行</td>
<tr><td>333</td> <td onclick="delrow(this)">点击删除此行</td>
</table><input type=button value="添加新行" onclick="addrow()">
function delrow(cellobj)
{
cellobj.parentNode.parentNode.deleteRow(cellobj.parentNode.rowIndex);
}function addrow()
{
var t=document.getElementById('table1'); //得到table引用
t.insertRow(t.rows.length); //插入空白行 var tcell;
tcell=t.rows[t.rows.length-1].insertCell(0) //插入单元格,并获取引用
tcell.appendChild(document.createTextNode('xxx')); //增加文本
tcell=t.rows[t.rows.length-1].insertCell(1)
tcell.appendChild(document.createTextNode('这是插入行'));
}
</script><table border=1 id="table1">
<tr><td>111</td> <td onclick="delrow(this)">点击删除此行</td>
<tr><td>222</td> <td onclick="delrow(this)">点击删除此行</td>
<tr><td>333</td> <td onclick="delrow(this)">点击删除此行</td>
</table><input type=button value="添加新行" onclick="addrow()">
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货