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("取消删除!");
}
}
【推荐】博客园的心动:当一群程序员决定开源共建一个真诚相亲平台
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】开源 Linux 服务器运维管理面板 1Panel V2 版本正式发布
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步