批量删除

接着上一篇博客

用户管理个人信息时用到了批量删除:

 1 $("#checkall").click(function(){ 
 2                 
 3                 var checkAll = $("#checkall").prop("checked");
 4               $("input[name='id[]']").prop("checked",checkAll);
 5             });
 6             //利用数组获取到所选复选框
 7             $("#deleteReplyAll").click(function(){
 8                 var chkValue = []; //数组啊
 9                 $("input[name='id[]']:checked").each(function(){//遍历被选中的复选框 
10                     chkValue.push($(this).val());//向数组中添加数据 
11                 }); 
12                 alert(chkValue);//弹出获取到的数组
13                 $.ajax({
14                     url : "${pageContext.request.contextPath}/deleteReplyAll.do",
15                     cache : false,
16                     type : 'post',
17                     data : {"replyArray":chkValue},
18                     //只有加了这句话ajax才能成功传递数组
19                     traditional: true,
20                     error : function() {
21                         alert('请求出错 了')
22                     },
23                     success : function(data) {
24                         replyuserpage(1);
25                     }
26                 });
27             });

几个简单的checkbox

1 <input type="checkbox" id="checkall" class="ace"/>
2 <input type="checkbox" class="ace" name="id[]" value="1"/>
3 <input type="checkbox" class="ace" name="id[]" value="2"/>
4 <input type="checkbox" class="ace" name="id[]" value="3"/>
5 <input type="checkbox" class="ace" name="id[]" value="4"/>
6 <input type="checkbox" class="ace" name="id[]" value="5"/>
7 <button type="button" id="deleteAll" class="btn btn-danger pull-right">批量删除</button>

后台controller

1 @RequestMapping("/deleteReplyAll")
2     public String deleteReplyAll(int[] replyArray){
3         for(int i=0;i<replyArray.length;i++){
4             int replyId = replyArray[i];
5             replyService.deleteReplyByReplyId(replyId);
6         }
7         return GERENTHIRD;
8     }

 

转载于:https://www.cnblogs.com/rendachang/p/7050558.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值