我想删除带有rowspan的选定行和一个额外的行,总共4行,您可以看到每4行堆栈代表1个条目。下面的函数 deleteSelectedRows() 不能正常工作;它只会删除选中的那个。能否请你帮忙!
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<table id="my_table" id="my_table" align="center" width="100%" border="1" cellpadding="0" cellspacing="0">
<tbody>
<thead>
<tr>
<th >No</th>
<th >Location</th>
<th >Time</th>
</tr>
<tr> <!-- new entry #1 -->
<td rowspan="3"><input type="checkbox">1a<td>
<td>1a</td>
</tr>
<tr>
<td>2a</td>
<td>2a</td>
</tr>
<tr>
<td>3a</td>
<td>3a</td>
</tr>
<tr >
<td colSpan="3">4a</td>
</tr>
<tr> <!-- new entry #2-->
<td rowspan="3"><input type="checkbox">1b<td>
<td>1b</td>
</tr>
<tr>
<td>2b</td>
<td>2b</td>
</tr>
<tr>
<td>3b</td>
<td>3b</td>
</tr>
<tr >
<td colSpan="3">4b</td>
</tr>
</thead></tbody>
</table>
<div><input type="button" value="Delete selected rows" onClick="deleteSelectedRows()"/></div>
</body>
</HTML>
<SCRIPT language="javascript">
function deleteSelectedRows() {
var table = document.getElementById('my_table'); //html table
var rowCount = table.rows.length; //no. of rows in table
for(var i=0; i< rowCount; i++) { //loops for all row in table
var row = table.rows[i]; //return a particular row
var chkbox = row.cells[0].childNodes[0]; //get check box onject
if(null != chkbox && true == chkbox.checked) { //wheather check box is selected
table.deleteRow(i); //delete the selected row
rowCount = rowCount-1; //decrease rowcount by 1
i--;
}
}
}
</script>