<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'process.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> <script type="text/javascript" src="jquery-1.4.1.js"></script> <script type="text/javascript"> </script> </head> <body> <table width="745" border="1" cellspacing="0"> <!--表头标题行--> <tr> <td>会员信息管理</td> </tr> <tr> <th width="84" scope="col"><a href="manager.jsp">删除/批量</a></th> <th width="146" scope="col">会员编号</th> <th width="92" scope="col">会员姓名</th> <th width="52" scope="col">会员性别</th> <th width="58" scope="col">联系电话</th> <th width="220" scope="col">Email地址</th> </tr> <c:forEach var="p" items="${requestScope.lst}"> <tr> <td><input type="checkbox" name="chose" /></td> <td>${p.userID}</td> <td>${p.userName}</td> <td>${p.userSex}</td> <td>${p.userPhone}</td> <td>${p.email}</td> </tr> </c:forEach> </table> </body> </html>
jQuery和Java的复选框问题
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
9条回答 默认 最新
- oxcow 2012-03-18 10:41关注
a.jsp[code="html"]<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
Insert title here $(function() { $("#allche").bind("click", function() { var ches = $(this).attr("checked"); if (!ches) { ches = false; } $.each($("#tCks :checkbox"), function(idx, val) { $(val).attr("checked", ches); }); }); $("#send").bind("click", function() { var aId = []; $.each($("#tCks :checked"), function(idx, val) { aId.push($(this).val()); }); if (aId.length == 0) { alert("请选择删除项"); return false; } var ids = aId.join(","); //使用1,或者使用2和3都可以 $(this).attr("href", "b.jsp?ids=" + ids); // 1 //window.location.href = "b.jsp?ids=" + ids; //2 //return false; // }); });
批量删除id name age
<%
for (int i = 1; i < 4; i++) {
%>http://www.w3.org/TR/html4/loose.dtd">
Insert title here
<%
String ids = request.getParameter("ids");
String[] aId = ids.split(",");
//拿到删除用户的id数组了,将aId传递到你的数据操作部分,进行删除即可。
%>
你要删除的用户ID为<%=ids%>
[/code]这里不管你是不是使用servlet还是jsp都是一样的。如果你使用的是servlet,那么把[code="js"]$(this).attr("href", "b.jsp?ids=" + ids);[/code]中的b.jsp换成你的servlet名称就行了,然后在该servlet中使用[code="java"]request.getParameter("ids");[/code]也就是b.jsp页面的代码进行获取就行了。最后将得到的id数组传到数据处理层进行处理就行了。
当然这里建议不要使用href的形式,你可以提供个form表单,把选中的值放在一个隐藏域中机型表单提交,那样做也是可以的,要改动的就是在js中拿到选择的checked值,也就是[code="js"]var aId = [];
$.each($("#tCks :checked"), function(idx, val) {
aId.push($(this).val());
});[/code]后,把aId.join(',')的值付给你的隐藏变量既可以,让后让form表单submit即可。这个你可以自己尝试下。我想我已经写的很明白了,如果还是弄不来那就再的无语了。呵呵,祝好运气了!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥15 安卓adb backup备份应用数据失败
- ¥15 eclipse运行项目时遇到的问题
- ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
- ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
- ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
- ¥50 成都蓉城足球俱乐部小程序抢票
- ¥15 yolov7训练自己的数据集
- ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
- ¥15 电力市场出清matlab yalmip kkt 双层优化问题
- ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)