後臺獲取js複選框checkbox批量刪除
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GBK">
<link href="/common/css/css.css" rel="stylesheet" type="text/css">
<script language="javascript" src="../js/servlet.js"></script>
<script language="javascript" src="../js/jquery-1.7.2.min.js"></script>
<title>郵件資訊管理</title>
<script type="text/javascript">
function entDeletes(){
//判斷至少寫了一項
var checkedNum = $("input[name='id']:checked").length;
if(checkedNum==0){
alert("請至少選擇一項!");
return false;
}
if(confirm("確定刪除所選專案?")){
var checkedList = new Array();
$("input[name='id']:checked").each(function(){
checkedList.push($(this).val());
});
}
$.ajax({
type:"POST",
url:'../ent/deleteEntAll',
data:{"delitems":checkedList.toString()},
datatype:"html",
success:function(data){
$("[name='checkbox2']:checkbox").attr("checked",false);
location.reload();//頁面重新整理
},
error:function(data){
art.dialog.tips('刪除失敗!');
}
});
}
</script>
</head>
=================================================================
<input type="button" value="刪除選中的企業" onclick="entDeletes()">
記得引入jqery檔案
mvc控制器獲取程式碼
@RequestMapping("/deleteEntAll")
public Msg deleteEntAll(HttpServletRequest request, HttpServletResponse response)throws Exception{
String items = request.getParameter("delitems");
System.out.println("對公押品批量刪除"+items);
String[] strs = items.split(",");
for (int i = 0; i < strs.length; i++) {
try {
String sub = strs[i];
String a =sub.substring(0, sub.length()-1);//取id最後又一個空格,用方法先處理,後期有時間再優化
// System.out.println("mumu======"+a);
entService.deleteEntAll(a);
} catch (Exception e) {
}
}
return Msg.success();
}