如题<table>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
</table>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
<tr>
<td><input type='button'/></td>
</tr>
</table>
table.deleteRow(0)//这里的数字是行的索引
tb.deleteRow(0)//这里的数字是行的索引
<table id='tab'>
<tr>
<td><input type='button' onclick='Delete(this.parentNode.parentNode);'/>
</td>
</tr></table>
this.parentNode.parentNode=tr节点
注意:有时候IE会把空格当成一个节点,所以你要具体调试下才清楚.大致方法是这样的
function Delete(theRow)
{
document.getElementById("tab").removeChild(theRow);
}
这个this.就是表示当前按钮,this.parentNode.parentNode就表示当前按钮的父节点的父节点
就是TR了,明白不
{
document.getElementById("tab").childNodes.removeChild(theRow);
}发现了,少加了个childNodes属性
debugger调试下
用JS实现!
<tr>
<td>
<input type="button" value="删除" onclick="javascript:this.parentNode.parentNode.parentNode.removeChild(this.parentNode.parentNode);" />
</td>
</tr>
<tr>
<td> <input type='button' onclick="delRow(this)"/> </td>
</tr></table>
function delRow(obj)
{
var Row=obj.parentNode;
while(Row.tagName.toLowerCase()!="tr")
{
Row=Row.parentNode;
}
Row.parentNode.removeChild(Row);//删除行}
<table><tr><td></td></tr></table>
在IE6会强行在<table>下加一个<tbody>标签,所以
你自已强行在<table>下加一个<tbody>标签
<table><tbody><tr><td>.....</td></tr></body></table>
然后将函数改为
function Delete(theRow)
{
document.getElementById("tab").childNodes[0].childNodes.removeChild(theRow);
}