按了顶上的删除(多项删除)

单列复选框删除 js语句

 <a href="javascript:delOne('${customer.id}')">删除</a></td>
 <script type="text/javascript">
function delOne(customerId)
{
var sure=window.confirm("确定删除么?");
if(sure)
{
window.location.href="${pageContext.request.contextPath}/DelCustomerServlet?customerId="+customerId;      //客户端转向servlet用于删除数据
}
}
</script>

多列复选框删除js语句

先在table外套个form表单 并且指定id,其中给复选框指定name 和 value

<td><input type="checkbox" name="ids" value="${customer.id}"/></td>

     <form action="${pageContext.request.contextPath }/DelCustomerServlet?method=delMultiple" id="form" method="post">
<table >
............
</table>
</form>
     <script type="text/javascript">
function delMultiple()
{
var ids=document.getElementsByName("ids");
var selected=false;
for(var i=0;i<ids.length;i++)
{
if(ids[i].checked)
{
selected=true;
break;
}
}
if(selected)
{
var sure=window.confirm("确定删除所选记录么?");
if(sure)
{
document.getElementById("form").submit();
}
}
else
{
alert("请先选择要删除的记录");
} }
</script>

参考

 <%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://www.WFReduceContent.com" prefix="reduce"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="${pageContext.request.contextPath }/DelCustomerServlet?method=delMultiple" id="form" method="post">
<table >
<tr>
<th><a href="${pageContext.request.contextPath}/HandleDispatchServlet?method=toAddCustomer">添加</a></th>
<th><a href="javascript:delMultiple()">多重删除</a></th>
</tr>
</table>
<table align ="center" cellpadding="5" border="4" >
<tr>
<th>选择</th>
<th>姓名</th>
<th>性别</th>
<th>生日</th>
<th>电话</th>
<th>email</th>
<th>爱好</th>
<th>类型</th>
<th>描述</th>
<th>操作</th>
</tr>
<c:forEach var="customer" items="${requestScope.customerList }" varStatus="status">
<tr bgcolor="${status.index%2==0?'red':'gray' }">
<td><input type="checkbox" name="ids" value="${customer.id}"/></td>
<td>${customer.name}</td>
<td>${customer.gender=="1"?"男":"女"}</td>
<td>${customer.birthday}</td>
<td>${customer.cellphone}</td>
<td>${customer.email}</td>
<td>${customer.hobby}</td>
<td>${customer.type}</td>
<td><reduce:reduceContent value="${customer.description}"/> </td>
<td><a href="${pageContext.request.contextPath}/HandleDispatchServlet?method=editCustomer&customerId=${customer.id}">编辑</a>
<a href="javascript:delOne('${customer.id}')">删除</a></td>
</tr>
</c:forEach>
</table>
<script type="text/javascript">
function delOne(customerId)
{
var sure=window.confirm("确定删除么?");
if(sure)
{
window.location.href="${pageContext.request.contextPath}/DelCustomerServlet?customerId="+customerId;
}
}
function delMultiple()
{
var ids=document.getElementsByName("ids");
var selected=false;
for(var i=0;i<ids.length;i++)
{
if(ids[i].checked)
{
selected=true;
break;
}
}
if(selected)
{
var sure=window.confirm("确定删除所选记录么?");
if(sure)
{
document.getElementById("form").submit();
}
}
else
{
alert("请先选择要删除的记录");
} }
</script>
</form>
</body> </html>
 package cn.itcast.Controller;

 import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import cn.itcast.service.CustomerService;
import cn.itcast.service.impl.CustomerServiceImpl; public class DelCustomerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private CustomerService service= new CustomerServiceImpl();
public DelCustomerServlet() {
super();
} protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String method=request.getParameter("method");
if("delMultiple".equals(method)) //多重删除
{
String ids[]=request.getParameterValues("ids");
if(null!=ids&&ids.length>0)
for(String id:ids)
service.delCustomerById(id);
request.getRequestDispatcher("ShowAllCustomer").forward(request, response);
return;
}
//单条删除
String customerId=request.getParameter("customerId");
System.out.println( "servlet"+customerId);
service.delCustomerById(customerId.trim());
request.getRequestDispatcher("ShowAllCustomer").forward(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
this.doGet(request, response);
} }

js 多选选择删除数据的更多相关文章

  1. JavaScript--动态添加元素(纯js书写table并删除数据)

    本文是对上一篇博文的扩展,用js书写表格,并添加和删除数据,详细代码解释见代码页. 对于文中使用的script脚本函数,下载地址如下:https://pan.baidu.com/s/13OFnj7nc ...

  2. JS多项选择删除

    $(document).ready(function(){ $("#batdel").click(function(){ var checkedLen = 0; var check ...

  3. JS中表格的全选和删除要注意的问题

    在项目开发中,由于刚刚开始做项目,我对js还不是很精通,所以在用js对表格的全选和删除中遇到了不少问题,后来通过查找资料解决了,之后总结了一下关于js表格的全选和删除出现的一些问题,希望能帮助到大家. ...

  4. easyui datagrid 通过复选框删除新追加的数据问题

    之前写好的功能在保存好数据后再通过复选框删除是没有问题的,可现在想多追加几行,然后选择删除新追加的某几行或一行,通过$('#dg').datagrid('getChecked')方法返回选中行,然而返 ...

  5. js 给json添加新的字段,或者添加一组数据,在JS数组指定位置删除、插入、替换元素

    JS定义了一个json数据var test={name:"name",age:"12"};需要给test再添加一个字段,需要什么办法,可以让test的值为{na ...

  6. [习题] FindControl 简单练习--GridView + CheckBox,点选多列数据(复选删除)#3 List或数组

    [习题] FindControl 简单练习--GridView + CheckBox,点选多列数据(复选删除)#3 List或数组 之前的范例,使用字符串.文字来记录将删除的文章ID 后续会有很多小缺 ...

  7. ASP.NET MVC搭建项目后台UI框架—8、将View中选择的数据行中的部分数据传入到Controller中

    目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...

  8. View中选择的数据行中的部分数据传入到Controller中

    将View中选择的数据行中的部分数据传入到Controller中   ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NE ...

  9. ASP.NET给DataGrid,Repeater等添加全选批量删除等功能

    很多情况下,在管理或者查看列表的时候我们需要很需要“全选”这个功能,这在ASP.NET中是非常容易实现的,下面我就将演示一点小代码实现这一功能.   实现全选的还是js的一个小函数:   [code] ...

随机推荐

  1. HTML5 本地存储(Web Storage)

    HTML5 提供了两种在客户端存储数据的新方法: localStorage - 本地永久存储,下次打开浏览器数据依然存在 sessionStorage - 只存在于一个会话的数据存储,关闭浏览器数据会 ...

  2. Digital controller compensates analog controller

    Emerging digital ICs for power control lack basic features, such as the built-in gate drive and curr ...

  3. eclipse中配置struts2出现There is no Action mapped for namespace [/] and action name [Login] associated wi

    下午在eclipse中配置struts2时报: There is no Action mapped for namespace [/] and action name [Login] associat ...

  4. ubuntu14.04 内核升级到 linux kernel 4.9

    http://blog.csdn.net/liuruiqun/article/details/55097292

  5. MySQL系列:innodb源码分析之内存管理

    http://blog.csdn.net/yuanrxdu/article/details/40985363 http://book.2cto.com/201402/40307.html 从MySQL ...

  6. Android与Unity交互研究

    转载请注明出处:http://blog.csdn.net/crazy1235/article/details/46733221 Android与Unity交互研究 unity与android交互的由来 ...

  7. 替换Android系统镜像system.img的方法

    之前改动了Android的系统源代码的framework层代码,定制ROM.通过make之后会生成三个镜像文件userdata.img.system.img.ramdisk.img三个文件.这个时候我 ...

  8. Python学习(七)面向对象 ——封装

    Python 类的封装 承接上一节,学了Student类的定义及实例化,每个实例都拥有各自的name和score.现在若需要打印一个学生的成绩,可定义函数 print_score() 该函数为类外的函 ...

  9. POJ 1737 Connected Graph 题解(未完成)

    Connected Graph Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 3156   Accepted: 1533 D ...

  10. Axure Beta 7.0 汉化版下载

    Axure的最新版本下载地址如下 安装文件地址: PC版下载地址:点我下载  Mac版下载地址:点我下载 下载后下载汉化包即可进行汉化(含中文部件库) 汉化文件:点我下载 -------------- ...