我是这样实现的,在生成button的时候,给每个button一个不同的ID,然后以这个ID做参数,onclick时触发此方法(注:这个button可是在<td></td>里面的)function deleteRow(elemId)
{
document.all.partline.deleteRow(document.getElementById(elemId).parentNode.parentNode.rowIndex);
}
{
document.all.partline.deleteRow(document.getElementById(elemId).parentNode.parentNode.rowIndex);
}
在button的onclick里tablename.deleteRow(this.parentNode.parentNode.rowIndex)
<head>
</head>
<body>
<table border="1" width="100%">
<tr>
<td width="20%">1 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B1" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">2 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B2" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">3 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B3" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">4 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B4" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">5 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B1" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">6 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B2" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">7 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B3" onClick="foo()"></td>
</tr>
<tr>
<td width="20%">8 </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"> </td>
<td width="20%"><input type="button" value="删除" name="B4" onClick="foo()"></td>
</tr>
</table>
<script>
function foo(){
var oElement = event.srcElement;
while(oElement.tagName != "TR"){
oElement = oElement.parentElement;
}
var oTBody = oElement.parentElement;
oTBody.removeChild(oElement)
}
</script>
</body></html>