jquery 批量删除
例子1:
全选
删除
<table>
<tr>
<td><input type="checkbox" id="checkall" name="checkall" onclick="checkAll()">全选 </td>
<td>姓名</td>
<td><a href="toadd.do">添加</a> </td>
</tr>
<tr>
<td><input type="checkbox" id="checkone" name="checkone" value="1"> </td>
<td>张三1</td>
</tr>
<tr>
<td><input type="checkbox" id="checkone" name="checkone" value="1"> </td>
<td>张三2</td>
</tr>
<tr>
<td><input type="checkbox" id="checkone" name="checkone" value="1"> </td>
<td>张三3</td>
</tr>
<tr>
<td><input type="checkbox" id="checkone" name="checkone" value="1"> </td>
<td>张三4</td>
</tr>
<td><input type="button" value="批量删除" onclick="del()"> </td>
</table>
//全选
function checkAll(){
$('[name="checkone"]').prop("checked",$('#checkAll')[0].checked);
}
======================
//如果有一个不选中 那么全选不勾选
function checkone(){
if($('[name="checkone"]').length==$('[name="checkone"]:checked').length){
$('#checkAll')[0].checked=true;
}else{
$('#checkAll')[0].checked=false;
}
}
// ============批量删除
function del(){
var ids=[];
//判断如果没选中 不让删除
if($('[name="checkone"]:checked').length==0){
alert("请选择要删除的内容!");
return;
}
var dl = confirm("确认要删除选中的内容吗?");
if(dl==true){
alert("确认删除!");
$('[name="checkone"]:checked').each(function(index,dd){
ids.push(dd.value);
})
location="bookAction_delete?ids="+ids.join()+"";
}else if(dl==false){
alert("取消删除!");
}
}