如何让动态表格能够动态地删除当前行
现在只能动态添加,删除只能从第一行开始删,代码有点长,各位大侠可以复制粘贴以下代码验证:<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>星级船舶考评表</title>
<script LANGUAGE="JavaScript">
var Clinum = 1;
function newRow()
{
var row= tbl.insertRow(-1); //添加行
row.height="28"; //设置行高
var cell1 = row.insertCell(0); //添加列
var cell2 = row.insertCell(1); //添加列
var cell3 = row.insertCell(2);
var cell4 = row.insertCell(3);
var cell5 = row.insertCell(4);
var cell6 = row.insertCell(5);
var cell7 = row.insertCell(6);
var cell8 = row.insertCell(7);
var cell9 = row.insertCell(8);
var cell10 = row.insertCell(9);
var cell11 = row.insertCell(10);
var cell12 = row.insertCell(11);
cell1.innerHTML="<center>"+""+"</center>";
cell2.innerHTML="<center>"+""+""+""+""+"</center>";
cell3.innerHTML="<center>"+""+"</center>";
cell4.innerHTML=" ";
cell5.innerHTML="<input type=button name=button1 id=button1 value=删除 onclick=deleteRow('tbl',this.parentElement.rowIndex) />";
cell6.innerHTML=" ";
cell7.innerHTML=" ";
cell8.innerHTML=" ";
cell9.innerHTML=" ";
cell10.innerHTML=" ";
cell11.innerHTML=" ";
cell12.innerHTML=" ";
}
function deleteRow (tableID,rowIndex)
{
var table = document.all[tableID];
table.deleteRow(rowIndex);
}
</script>
</head>
<body>
<form>
<table width="900" border="1" cellpadding="0" cellspacing="0" bordercolor="#000000" id="tbl" align="center">
<!--DWLayoutTable-->
<tr>
<td width="110" height="28" align="center" valign="middle">部门</td>
<td width="163" align="center" valign="middle"><span class="STYLE5">项目</span>
<label></label></td>
<td align="center" valign="middle">序号</td>
<td width="41" align="center" valign="middle">内容</td>
<td width="41" align="center" valign="middle">状态</td>
<td width="105" align="center" valign="middle"><span class="STYLE5">分值</span></td>
<td width="81" align="center" valign="middle">船舶责任人</td>
<td width="82" align="center" valign="middle">船舶监督人</td>
<td width="68" align="center" valign="middle">自评扣分</td>
<td width="68" align="center" valign="middle">考评扣分</td>
<td width="68" align="center" valign="middle">备注</td>
<td width="68" align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
</tr>
<tr>
<td height="28" align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><label></label></td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle" onclick="deleteRow('tbl',this.parentElement.rowIndex)">删除行</td>
<td align="center" valign="middle"><label></label></td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle"><!--DWLayoutEmptyCell--> </td>
<td align="center" valign="middle">添加内容请按<strong>→</strong>
<label>
<input type="button" name="button" id="button" value="添加" onclick="newRow()"/>
</label></td>
</tr>
</table>
</form>
</body>
</html>