通过checkboxs动态删除多行tr

<html>
<head>
<script>
 function delte() {
  var checkboxs = document.getElementsByName("c1");
  var table  = document.getElementById("mytable"); 
  var allTrlength = table.rows.length;
  var trIndex ;
  for(var i=0; i<checkboxs.length; i++) {
    for(var j=allTrlength - 1; j>0 ;j--) {
   if(checkboxs[i].checked == true) {
    table.deleteRow(checkboxs[i].parentNode.parentNode.rowIndex);
    } 
   }
  }
 }
</script>
</head>
<body>
<table id="mytable">
<tr><td><input type="checkbox" name="c1"></td>
</tr>
<tr><td><input type="checkbox" name="c1"></td>
</tr>
<tr><td><input type="checkbox" name="c1"></td>
</tr>
<tr><td><input type="checkbox" name="c1"></td>
</tr>
<tr><td><input type="checkbox" name="c1"></td>
</tr>
<tr><td><input type="checkbox" name="c1"></td>
</tr>
</table>
<input type="button" value="delete" onclick="delte();">
</body>
</html>

你可能感兴趣的:(script)