批量删除
接着上一篇博客
用户管理个人信息时用到了批量删除:
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 }