批量删除(spring mvc )
来源:互联网 发布:西门子编程电缆多少钱 编辑:程序博客网 时间:2024/06/05 13:31
// JavaScript Document
$(document).ready(function() {
// 全选
$("#allChk").click(function() {
$("input[name='subChk']").prop("checked",this.checked);
});
// 单选
var subChk = $("input[name='subChk']")
subChk.click(function() {
$("#allChk").prop("checked", subChk.length == subChk.filter(":checked").length ? true:false);
});
/* 批量删除 */
$("#del_model").click(function() {
// 判断是否至少选择一项
var checkedNum = $("input[name='subChk']:checked").length;
if(checkedNum == 0) {
alert("请选择至少一项!");
return;
}
// 批量选择
if(confirm("确定要删除所选项目?")) {
var checkedList = new Array();
$("input[name='subChk']:checked").each(function() {
checkedList.push($(this).val());
});
$.ajax({
type: "POST",
url: "deletemore",
data: {'delitems':checkedList.toString()},
success: function(result) {
$("[name ='subChk']:checkbox").attr("checked", false);
window.location.reload();
}
});
}
});
});
页面元素:
<a href="#" id="del_model"><span>删除用户</span>
<th class="tal"><input type="checkbox" id="allChk"/>全选</th>
<td><input type="checkbox" name="subChk" value="${user.id}"/></td>
$(document).ready(function() {
// 全选
$("#allChk").click(function() {
$("input[name='subChk']").prop("checked",this.checked);
});
// 单选
var subChk = $("input[name='subChk']")
subChk.click(function() {
$("#allChk").prop("checked", subChk.length == subChk.filter(":checked").length ? true:false);
});
/* 批量删除 */
$("#del_model").click(function() {
// 判断是否至少选择一项
var checkedNum = $("input[name='subChk']:checked").length;
if(checkedNum == 0) {
alert("请选择至少一项!");
return;
}
// 批量选择
if(confirm("确定要删除所选项目?")) {
var checkedList = new Array();
$("input[name='subChk']:checked").each(function() {
checkedList.push($(this).val());
});
$.ajax({
type: "POST",
url: "deletemore",
data: {'delitems':checkedList.toString()},
success: function(result) {
$("[name ='subChk']:checkbox").attr("checked", false);
window.location.reload();
}
});
}
});
});
页面元素:
<a href="#" id="del_model"><span>删除用户</span>
<th class="tal"><input type="checkbox" id="allChk"/>全选</th>
<td><input type="checkbox" name="subChk" value="${user.id}"/></td>
回调函数,在请求完成后需要进行的操作:此处是把选中的checkbox去掉(因为是用到了freemarker的list循环,去掉是数据后checkbox序号变化,还有有相应未知的checkbox被选中,需要去掉)。
复制代码 代码如下:
success: function(result) {
$("[name = 'items']:checkbox").attr("checked", false);
window.location.reload();
}
java后台代码:
复制代码 代码如下:
@RequestMapping(value = "/deletemore", method = RequestMethod.POST)
public String deleteMore(HttpServletRequest request, HttpServletResponse response) {
String items = request.getParameter("delitems");
String[] item = items.split(",");
for (int i = 0; i < item.length; i++) {
userService.delete(Integer.parseInt(item[i]));
}
return "redirect:list";
}
0 1
- 批量删除(spring mvc )
- spring mvc接收数组mybatis 接收批量删除代码
- 基于Spring MVC + Mybatis实现多选框批量删除
- Spring mvc批量图片上传
- asp.net mvc批量删除的实现
- MVC jquery ajax 批量删除数据
- spring mvc 批量上传+文件上传
- spring mvc 批量上传+文件上传
- spring mvc 批量上传+文件上传
- Spring mvc批量插入sql配置
- 【spring+hibernate学习文档】---批量更新和批量删除
- spring(基础21) hibernate处理批量更新和批量删除
- 基于注解的Spring MVC整合Hibernate(所需jar包,spring和Hibernate整合配置,springMVC配置,重定向,批量删除)
- 《MVC + EF+ WCF 》——批量删除数据
- spring mvc 下的mysql+mybatis批量更新
- spring mvc 批量下载压缩文件夹中文件
- 单条/批量增加信息,Spring MVC, Mybatis, MySQL
- 批量删除
- 欢迎使用CSDN-markdown编辑器
- Java集合的小抄,Java初学者必备
- this、super对照
- jQuery轻量级弹窗
- 写一句中文放入文件
- 批量删除(spring mvc )
- 堆栈的操作
- 蓝桥杯单片机学习1
- 方法重写、方法重载
- flask重置密码功能的实现
- 413. Arithmetic Slices
- Lightoj1018 【状压DP】
- python中lambda函数
- Unix目录结构的来历