为何多行删除不了,且报错
<script>
function delselchk()
{
var obj = document.getElementsByName( "chkt1 ");
var tb1=document.getElementById( "tb1 ");
var objLen= obj.length;
for (var i=0; i <objLen;i++)
{
if(obj[i].checked==true)
{
tb1.deleteRow(document.getElementById(obj[i].value).rowIndex);
}
}
}
</script>
<body>
<table name= "tb1 " id= "tb1 " border=1>
<tr>
<td id= "tr1 " name= "tr1 "> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr1 "> </td>
<td> 第一行 </td>
</tr>
<tr id= "tr2 " name= "tr2 ">
<td> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr2 "> </td>
<td> 第二行 </td>
</tr>
<tr id= "tr3 " name= "tr3 ">
<td> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr3 "> </td>
<td> 第三行 </td>
</tr>
</table>
<input type= "button " onclick= "delselchk() " value= "选择后删除 ">
</body>
------解决方案------------------------这样就可以了-----
<script>
function delselchk()
{
var obj = document.getElementsByName( "chkt1 ");
var tb1=document.getElementById( "tb1 ");
var objLen= obj.length;
for (var i=objLen-1; i> -1;i--)
{
if(obj[i].checked==true)
{
tb1.deleteRow(document.getElementById(obj[i].value).rowIndex);
}
}
}
</script>
<body>
<table name= "tb1 " id= "tb1 " border=1>
<tr>
<td id= "tr1 " name= "tr1 "> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr1 "> </td>
<td> 第一行 </td>
</tr>
<tr id= "tr2 " name= "tr2 ">
<td> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr2 "> </td>
<td> 第二行 </td>
</tr>
<tr id= "tr3 " name= "tr3 ">
<td> <input type= "checkBox " name= "chkt1 " id= "chkt1 " value= "tr3 "> </td>
<td> 第三行 </td>
</tr>
</table>
<input type= "button " onClick= "delselchk() " value= "选择后删除 ">
</body>