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

单列复选框删除 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. 树莓派(Debian)系统设置了静态IP之后还会获取动态IP的问题解决(scope global secondary eth0)

    解决方法: 1.配置好静态IP在/etc/network/interface 2.关闭dhcp服务(不知道这个服务是干嘛的,明明是客户端还需要这个) sudo systemctl stop dhcpc ...

  2. It's a Buck; It's a Boost, No! It's a Switcher!

    It's a Buck; It's a Boost, No! It's a Switcher! Sanjaya Maniktala, National Semiconductor Corp., San ...

  3. Circuit translates I2C voltages

    This Design Idea explores level-shifting an I2C bus from 5V/ground (positive domain) to ground/–5V ( ...

  4. 东东糖博客MYSQL

    http://blog.chinaunix.net/uid-20785090-id-4328033.html

  5. 移动端 关于 键盘将input 框 顶上去的解决思路---个人见解

    在移动端,经常会遇到input获得焦点时候弹出的虚拟键盘将整体页面布局打乱的情况. 比如说是这种 输入框未获得焦点键盘未抬起的时候: 输入框获得焦点键盘抬起的时候 这种情况下,不管是上面的textar ...

  6. NHibernate 3 Beginner's Guide

    前言 这一章是一个完整的NHibernate的Simple,原文中用Fluent NHibernate做映射,但我使用NHibernate3.2版本,所以3.2的Conformist代替Fluent ...

  7. JAVA RMI调用实战学习

    JAVA RMI 实战示例,参考网址: http://diaoge.iteye.com/blog/245170 这个示例很清楚地阐释了rmi的使用方法, 但示例都是放在一起的, 实际使用中我们可能会将 ...

  8. 【java】【mysql】存储微信表情emoji表情

    java.sql.SQLException: Incorrect string value: '\xF0\x9F\x92\x94' for colum n 'name' at row 1 at com ...

  9. 使用OllyDbg破解软件

    好,废话不多说,教程开始.  我们首先查壳,是Aspark的壳,对于这个壳,大家应该很熟了.<ignore_js_op>   我已经脱好了壳,再查一下壳,是Dephi的<ignore ...

  10. zendframework配置篇

    1. 重写配置 httpd.conf配置修改 LoadModule rewrite_module modules/mod_rewrite.so <Directory "D:\PHPPr ...