1.以批量删除为例,这里直接诶操作数据库了,实际不这么做,只是为了演示效果。
<table >
<thead >
<tr>
<th ><input type="checkbox" id="all"/></th>
<th>ID</th>
<th>名称</th>
</tr>
</thead>
<tbody >
<c:forEach items="${pageBean.data}" var="entry">
<tr>
<td><input type="checkbox" value="${entry.id }" name="ids"/></td>
<td align="center">${entry.id }</td>
<td align="center">${entry.name }</td>
</tr>
</c:forEach>
</tbody>
</table>
<div><input class="del-button" type="button" value="删除" "/></div>
$(function(){
$('#all').click(function(){
$('input[type=checkbox]').attr('checked', $(this).attr('checked'));
});
$('.del-button').click(function(){
var chckBox = document.getElementsByName("ids");
var num = chckBox.length;
var ids = "";
for(var index =0 ; index<num ; index++){
if(chckBox[index].checked){
ids += chckBox[index].value + ",";
}
}
console.log(ids);
if(ids!=""){
if(window.confirm("确定删除所选记录?")){
$.ajax( {
type : "post",
url : "URL?ids="+ ids,
dataType : "text",
success : function(data) {
alert(data);
window.location.href = "goList.html" ;
},
error : function(data) {
alert("系统错误,删除失败");
}
});
}
}else{
alert("请选择要删除的记录");
}
});
});
@RequestMapping("/URL")
@ResponseBody
public String deleMore(String ids){
System.out.println(ids);
String[] split = ids.split(",");
for (int i = 0; i < split.length; i++) {
//删除 service.deleBrandById(Integer.parseInt(split[i]));
}
return "ok";
}