JS的复选框批量删除问题
<html><head></head><body><scriptlanguage="javascript">functiondeleteAll(obj){varcheck...
<html>
<head>
</head>
<body>
<script language="javascript">
function deleteAll(obj){
var checked = document.getElementsByName(obj);
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=obj.parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
}
}
</script>
<table name="table_name" id="table_id" border width=330 height=30 style="border:1px solid #000000">
<tr>
<td> </td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input type="button" name="delete_button" value="批量删除" onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</ html>
怎么我的批量删除功能实现不了呢?在线等 展开
<head>
</head>
<body>
<script language="javascript">
function deleteAll(obj){
var checked = document.getElementsByName(obj);
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=obj.parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
}
}
</script>
<table name="table_name" id="table_id" border width=330 height=30 style="border:1px solid #000000">
<tr>
<td> </td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input type="button" name="delete_button" value="批量删除" onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</ html>
怎么我的批量删除功能实现不了呢?在线等 展开
展开全部
<html>
<head>
</head>
<body>
<script language="javascript">
function deleteAll(obj){
var checked = document.getElementsByName(obj);
debugger
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
i--;
}
}
}
</script>
<table name="table_name" id="table_id" border width=330 height=30 style="border:1px solid #000000">
<tr>
<td> </td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input type="button" name="delete_button" value="批量删除" onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</ html>
<head>
</head>
<body>
<script language="javascript">
function deleteAll(obj){
var checked = document.getElementsByName(obj);
debugger
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
i--;
}
}
}
</script>
<table name="table_name" id="table_id" border width=330 height=30 style="border:1px solid #000000">
<tr>
<td> </td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT type="checkbox" name="range" value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input type="button" name="delete_button" value="批量删除" onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</ html>
展开全部
<html>
<head>
</head>
<body>
<script
language="javascript">
function
deleteAll(obj){
var
checked
=
document.getElementsByName(obj);
debugger
for(var
i
=
0;
i
<
checked.length;
i
++){
if(checked[i].checked){
var
tr=checked[i].parentNode.parentNode;
var
tbody=tr.parentNode;
tbody.removeChild(tr);
i--;
}
}
}
</script>
<table
name="table_name"
id="table_id"
border
width=330
height=30
style="border:1px
solid
#000000">
<tr>
<td>
</td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input
type="button"
name="delete_button"
value="批量删除"
onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</
html>
<head>
</head>
<body>
<script
language="javascript">
function
deleteAll(obj){
var
checked
=
document.getElementsByName(obj);
debugger
for(var
i
=
0;
i
<
checked.length;
i
++){
if(checked[i].checked){
var
tr=checked[i].parentNode.parentNode;
var
tbody=tr.parentNode;
tbody.removeChild(tr);
i--;
}
}
}
</script>
<table
name="table_name"
id="table_id"
border
width=330
height=30
style="border:1px
solid
#000000">
<tr>
<td>
</td>
<td>分组名字</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="a"></td>
<td>a</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="b"></td>
<td>b</td>
</tr>
<tr>
<td><INPUT
type="checkbox"
name="range"
value="c"></td>
<td>c</td>
</tr>
</tbody>
<tr>
<td>
</td>
<td><input
type="button"
name="delete_button"
value="批量删除"
onclick="deleteAll('range');">
</td>
</tr>
</table>
</body>
</
html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那个函数有问题,是checked[i],不是obj
function deleteAll(obj){
var checked = document.getElementsByName(obj);
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
}
}
function deleteAll(obj){
var checked = document.getElementsByName(obj);
for(var i = 0; i < checked.length; i ++){
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode;
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你JS写错了。
更正如下部分:
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode; //obj是你传入的字符串,checked[i]才是checkbox控件
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
更正如下部分:
if(checked[i].checked){
var tr=checked[i].parentNode.parentNode; //obj是你传入的字符串,checked[i]才是checkbox控件
var tbody=tr.parentNode;
tbody.removeChild(tr);
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询