//CSS
<style type="text/css">
body{ font-size:12px;}
table{ border-collapse:collapse;}
td,th{ line-height:3; border:1px solid #ccc; text-align:center;}
td span{ margin-right:30px;}
th{ background-color:#999; color:#FFFFFF;}
</style>//HTML代码<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<th>选项</th>
<th>编号</th>
<th>封面</th>
<th>购书人</th>
<th>性别</th>
<th>购书价</th>
</tr>
<tr id="0">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1001</td>
<td> </td>
<td>李小明</td>
<td>男</td>
<td>32.50元</td>
</tr>
<tr id="1">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1002</td>
<td> </td>
<td>张小娴</td>
<td>男</td>
<td>54.90元</td>
</tr>
<tr id="2">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1003</td>
<td> </td>
<td>张晓星</td>
<td>女</td>
<td>120.30元</td>
</tr>
<tr id="3">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1004</td>
<td> </td>
<td>刘清清</td>
<td>女</td>
<td>68.00元</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td colspan="6"><span><label for="chkAll"><input type="checkbox" id="chkAll" value="0" />全选</label></span><span><input type="button" id="btnDel" value="删除" /></span></td>
</tr>
</table>//jQuery代码<script type="text/javascript"> $(function(){
$("table tr:nth-child(even):not(:last)").css("background-color","#F7FFF7");//隔行换色
//全选按钮单机事件
$("#chkAll").click(function(){
if(this.checked){
$("table tr td input[type=checkbox]").attr("checked",true);
}
else{
$("table tr td input[type=checkbox]").attr("checked",false);
}
});
//删除按钮单机事件
$("#btnDel").click(function(){
var intL = $("table tr td input:checked:not('#chkAll')").length;//获取除全选复选框外的所有选中项
if(intL!=0){//如果有选中项
$("table tr td input[type=checkbox]:not('#chkAll')").each(function(index){
if(this.checked){//如果选中
$("table tr[id=" + this.value + "]").remove();//获取选中的值,并删除该值所在的行
}
})
}
});
})
</script>
出现问题,当全选后,单击全部删除按扭,却只能删除一个,这是哪里的问题啊!请解?谢谢了!
<style type="text/css">
body{ font-size:12px;}
table{ border-collapse:collapse;}
td,th{ line-height:3; border:1px solid #ccc; text-align:center;}
td span{ margin-right:30px;}
th{ background-color:#999; color:#FFFFFF;}
</style>//HTML代码<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<th>选项</th>
<th>编号</th>
<th>封面</th>
<th>购书人</th>
<th>性别</th>
<th>购书价</th>
</tr>
<tr id="0">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1001</td>
<td> </td>
<td>李小明</td>
<td>男</td>
<td>32.50元</td>
</tr>
<tr id="1">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1002</td>
<td> </td>
<td>张小娴</td>
<td>男</td>
<td>54.90元</td>
</tr>
<tr id="2">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1003</td>
<td> </td>
<td>张晓星</td>
<td>女</td>
<td>120.30元</td>
</tr>
<tr id="3">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1004</td>
<td> </td>
<td>刘清清</td>
<td>女</td>
<td>68.00元</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td colspan="6"><span><label for="chkAll"><input type="checkbox" id="chkAll" value="0" />全选</label></span><span><input type="button" id="btnDel" value="删除" /></span></td>
</tr>
</table>//jQuery代码<script type="text/javascript"> $(function(){
$("table tr:nth-child(even):not(:last)").css("background-color","#F7FFF7");//隔行换色
//全选按钮单机事件
$("#chkAll").click(function(){
if(this.checked){
$("table tr td input[type=checkbox]").attr("checked",true);
}
else{
$("table tr td input[type=checkbox]").attr("checked",false);
}
});
//删除按钮单机事件
$("#btnDel").click(function(){
var intL = $("table tr td input:checked:not('#chkAll')").length;//获取除全选复选框外的所有选中项
if(intL!=0){//如果有选中项
$("table tr td input[type=checkbox]:not('#chkAll')").each(function(index){
if(this.checked){//如果选中
$("table tr[id=" + this.value + "]").remove();//获取选中的值,并删除该值所在的行
}
})
}
});
})
</script>
出现问题,当全选后,单击全部删除按扭,却只能删除一个,这是哪里的问题啊!请解?谢谢了!
if(intL!=0){//如果有选中项
$("table tr td input[type=checkbox]:not('#chkAll')").each(function(index){
if(this.checked){//如果选中
$("table tr[id=" + this.value + "]").remove();//获取选中的值,并删除该值所在的行
<style type="text/css">
body{ font-size:12px;}
table{ border-collapse:collapse;}
td,th{ line-height:3; border:1px solid #ccc; text-align:center;}
td span{ margin-right:30px;}
th{ background-color:#999; color:#FFFFFF;}
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/JavaScript">
$(function(){ $("table tr:nth-child(even):not(:last)").css("background-color","#F7FFF7");//隔行换色//全选按钮单机事件
$("#chkAll").click(function(){ if(this.checked){
$("table tr td input[type=checkbox]").attr("checked",true);
}
else{
$("table tr td input[type=checkbox]").attr("checked",false);
}
}); //删除按钮单机事件
$("#btnDel").click(function(){ var intL = $("table tr td input:checked:not('#chkAll')").length;//获取除全选复选框外的所有选中项
//alert(intL);
if(intL!=0){//如果有选中项
$("table tr td input[type=checkbox]:not('#chkAll')").each(function(index,value){
if(this.checked){//如果选中
//alert(this.value);
$("table tr[id=" + this.value + "]").remove();//获取选中的值,并删除该值所在的行
//$("tr").eq($(this)).remove();
}
})
}
});
})
</script>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<th>选项</th>
<th>编号</th>
<th>封面</th>
<th>购书人</th>
<th>性别</th>
<th>购书价</th>
</tr>
<tr id="0">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1001</td>
<td> </td>
<td>李小明</td>
<td>男</td>
<td>32.50元</td>
</tr>
<tr id="1">
<td><input type="checkbox" id="checkbox1" value="1" /></td>
<td>1002</td>
<td> </td>
<td>张小娴</td>
<td>男</td>
<td>54.90元</td>
</tr>
<tr id="2">
<td><input type="checkbox" id="checkbox1" value="2" /></td>
<td>1003</td>
<td> </td>
<td>张晓星</td>
<td>女</td>
<td>120.30元</td>
</tr>
<tr id="3">
<td><input type="checkbox" id="checkbox1" value="3" /></td>
<td>1004</td>
<td> </td>
<td>刘清清</td>
<td>女</td>
<td>68.00元</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td colspan="6"><span><label for="chkAll"><input type="checkbox" id="chkAll" value="0" />全选</label></span><span><input type="button" id="btnDel" value="删除" /></span></td>
</tr>
</table>
<td><input type="checkbox" id="checkbox1" value="3" /></td>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="scripts/jquery-1.4.4.min.js"></script>
<style type="text/css">
body{ font-size:12px;}
table{ border-collapse:collapse;}
td,th{ line-height:3; border:1px solid #ccc; text-align:center;}
td span{ margin-right:30px;}
th{ background-color:#999; color:#FFFFFF;}
</style>
</head><body>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<th>选项</th>
<th>编号</th>
<th>封面</th>
<th>购书人</th>
<th>性别</th>
<th>购书价</th>
</tr>
<tr id="0">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1001</td>
<td> </td>
<td>李小明</td>
<td>男</td>
<td>32.50元</td>
</tr>
<tr id="1">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1002</td>
<td> </td>
<td>张小娴</td>
<td>男</td>
<td>54.90元</td>
</tr>
<tr id="2">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1003</td>
<td> </td>
<td>张晓星</td>
<td>女</td>
<td>120.30元</td>
</tr>
<tr id="3">
<td><input type="checkbox" id="checkbox1" value="0" /></td>
<td>1004</td>
<td> </td>
<td>刘清清</td>
<td>女</td>
<td>68.00元</td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="600">
<tr>
<td colspan="6"><span><label for="chkAll"><input type="checkbox" id="chkAll" value="0" />全选</label></span><span><input type="button" id="btnDel" value="删除" /></span></td>
</tr>
</table>//jQuery代码<script type="text/javascript">$(function(){$("table tr:nth-child(even):not(:last)").css("background-color","#F7FFF7");//隔行换色//全选按钮单机事件
$("#chkAll").click(function(){if(this.checked){
$("table tr td input[type=checkbox]").attr("checked",true);
}
else{
$("table tr td input[type=checkbox]").attr("checked",false);
}
});//删除按钮单机事件
$("#btnDel").click(function(){var intL = $("table tr td input:checked(:not('#chkAll'))").length;//获取除全选复选框外的所有选中项
if(intL!=0){//如果有选中项
$("table tr td input[type=checkbox]:not('#chkAll')").each(function(index){
if(this.checked){//如果选中
//$("table tr[id=" + this.value + "]").remove();//获取选中的值,并删除该值所在的行
$(this).parent().parent().remove();
}
})
}
});
})
</script></body>
</html>
原因是value都为0,只获得了第一个