删除被选中的checkbox对应的行

  • Post author:
  • Post category:其他



<SCRIPT LANGUAGE="JavaScript">
<!--
function deleteRows(){
var rows = document.detailForm.detail;
var detailTable = document.getElementById("detailTable");
for(var i=0; i<rows.length; i++){
if(rows[i].checked){
detailTable.deleteRow(rows[i].parentNode.parentNode.rowIndex);
i--;
}
}
}

//-->
</SCRIPT>
<BODY>
<FORM METHOD=POST ACTION="" name="detailForm">
<TABLE id="detailTable">
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>
<TR>
<TD><INPUT TYPE="checkbox" NAME="detail"></TD>
</TR>

</TABLE>
<INPUT TYPE="button" VALUE="delete" ONCLICK="deleteRows()">
</FORM>

刚刚看到逆水行舟中做这样的处理。感觉又学到了些。不过当checkbox只有一个得时候getElementById得到的不是数组。mark下。