js 多选选择删除数据
按了顶上的删除(多项删除)

单列复选框删除 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 多选选择删除数据的更多相关文章
- JavaScript--动态添加元素(纯js书写table并删除数据)
本文是对上一篇博文的扩展,用js书写表格,并添加和删除数据,详细代码解释见代码页. 对于文中使用的script脚本函数,下载地址如下:https://pan.baidu.com/s/13OFnj7nc ...
- JS多项选择删除
$(document).ready(function(){ $("#batdel").click(function(){ var checkedLen = 0; var check ...
- JS中表格的全选和删除要注意的问题
在项目开发中,由于刚刚开始做项目,我对js还不是很精通,所以在用js对表格的全选和删除中遇到了不少问题,后来通过查找资料解决了,之后总结了一下关于js表格的全选和删除出现的一些问题,希望能帮助到大家. ...
- easyui datagrid 通过复选框删除新追加的数据问题
之前写好的功能在保存好数据后再通过复选框删除是没有问题的,可现在想多追加几行,然后选择删除新追加的某几行或一行,通过$('#dg').datagrid('getChecked')方法返回选中行,然而返 ...
- js 给json添加新的字段,或者添加一组数据,在JS数组指定位置删除、插入、替换元素
JS定义了一个json数据var test={name:"name",age:"12"};需要给test再添加一个字段,需要什么办法,可以让test的值为{na ...
- [习题] FindControl 简单练习--GridView + CheckBox,点选多列数据(复选删除)#3 List或数组
[习题] FindControl 简单练习--GridView + CheckBox,点选多列数据(复选删除)#3 List或数组 之前的范例,使用字符串.文字来记录将删除的文章ID 后续会有很多小缺 ...
- ASP.NET MVC搭建项目后台UI框架—8、将View中选择的数据行中的部分数据传入到Controller中
目录 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NET MVC搭建项目后台UI框架—3.面板折叠和展开 ASP.NE ...
- View中选择的数据行中的部分数据传入到Controller中
将View中选择的数据行中的部分数据传入到Controller中 ASP.NET MVC搭建项目后台UI框架—1.后台主框架 ASP.NET MVC搭建项目后台UI框架—2.菜单特效 ASP.NE ...
- ASP.NET给DataGrid,Repeater等添加全选批量删除等功能
很多情况下,在管理或者查看列表的时候我们需要很需要“全选”这个功能,这在ASP.NET中是非常容易实现的,下面我就将演示一点小代码实现这一功能. 实现全选的还是js的一个小函数: [code] ...
随机推荐
- Ubuntu14.04环境下配置TFTP服务器
<<<<<<<<<<<<<<<<<<<<<<<<< ...
- 腾讯PHP工程师面试题两份
试题一: PHP开发工程师笔试试卷 姓名:__________ 一.PHP开发部分 1.合并两个数组有几种方式,试比较它们的异同 2.请写一个函数来检查用户提交的数据是否为整数(不区分数据类型,可以为 ...
- crtmpserver 在VS2010下的build
Make sure that you have administrative privileges before doing the following steps.1. 下载并安装(Microso ...
- centos7 yum安装配置redis 并设置密码
原文:https://www.cnblogs.com/fanlinglong/p/6635828.html centos7 yum安装配置redis 并设置密码 1.设置Redis的仓库地址 yum ...
- ASP.NET 5 的Roadmap(转)
这次随 Visual Studio 2015 发布的 ASP.NET 版本是 ASP.NET 4.6 与 ASP.NET 5 beta5.在 VS2015 发布的同时,微软也发布了 ASP.NET 5 ...
- 使用SQL查询连续号码段
原文http://www.cnblogs.com/tc310/archive/2010/09/17/1829276.html CREATE TABLE #test(fphm INT ,kshm CHA ...
- WebSocket原理分析
Web应用的通信过程通常是客户端通过浏览器发出一个请求,服务器端接收请求后进行处理并返回结果给客户端,客户端浏览器将信息呈现.这种机制对于信息变化不是特别频繁的应用可以良好支撑,但对于实时要求高.海量 ...
- 飘逸的python - 不使用keyword,求和1+2+…+n
依据题意,我们不能用到if/else/for/while等keyword. --------------思考中------------ 思路: 1.用递归实现循环 2.递归的终止条件不用if怎么推断呢 ...
- [AngularJS] $scope.$warchCollection
For the $watch in last article, we watch 'user.password', actually it is a string. If you watch 'use ...
- 【pyhon】nvshens按目录图片批量下载爬虫1.00(多线程版)
# nvshens按目录图片批量下载爬虫1.00(多线程版) from bs4 import BeautifulSoup import requests import datetime import ...