html checkbox mysql_html table中嵌入checkbox实现全选 | 学步园

pageEncoding="utf-8"%>

Connection ct = null;

PreparedStatement ps = null;

ResultSet rs = null;

String DRIVER = "com.mysql.jdbc.Driver";

String URL = "jdbc:mysql://localhost:3306/smg";

String USERNAME = "root";

String PASSWD = "root";

List orderDetailList = new ArrayList();

String doflag = request.getParameter("doflag");

if(doflag==null||doflag.length()==0) {

try {

Class.forName(DRIVER);

ct = DriverManager.getConnection(URL, USERNAME, PASSWD);

String orderIds = request.getParameter("orderIds");

if(null != orderIds && !orderIds.isEmpty()) {

System.out.println(orderIds.length());

System.out.println(orderIds);

StringBuilder sb = new StringBuilder();

String str = "(";

for(int i=0;i

if(',' != orderIds.charAt(i)) {

sb.append(orderIds.charAt(i));

if(i == orderIds.length() - 1) {

str = str + "'"+sb+"'";

}

} else {

str = str + "'"+sb+"'" + ",";

sb = new StringBuilder();

}

}

str = str + ")";

System.out.println(str);

//查出所有orderId对应的列 表

String sql = "select * from ordDetail where orderId in " +str;

ps = ct.prepareStatement(sql);

rs = ps.executeQuery();

while(rs.next()) {

OrderDetail orderDetail = new OrderDetail();

orderDetail.setId(rs.getInt("id"));

orderDetail.setOrderId(rs.getString("orderId"));

orderDetail.setName(rs.getString("name"));

orderDetail.setAddress(rs.getString("address"));

orderDetail.setFlag(rs.getInt("flag"));

orderDetailList.add(orderDetail);

}

}

} catch (Exception e) {

e.printStackTrace();

} finally {

}

} else if("update".equals(doflag)) {

try {

Class.forName(DRIVER);

ct = DriverManager.getConnection(URL, USERNAME, PASSWD);

//根据获取的flag判断是否提交并获取提交的checkbox

String ids[] = request.getParameterValues("mycheckbox");

//拼接sql语句

StringBuilder sb = new StringBuilder();

String str = "";

if(null != ids && ids.length != 0) {

sb.append("(");

for(String id : ids) {

sb.append("'"+id+"'");

sb.append(",");

}

str = sb.substring(0,sb.length()-1).toString();

str = str + ")";

//根据id更新数据

String sqlStr = "update ordDetail set flag = 1 - flag where id in "+str;

System.out.println(sqlStr);

ps = ct.prepareStatement(sqlStr);

ps.execute();

request.setAttribute("resultflag", "save" );

}

} catch(Exception e) {

request.setAttribute("resultflag", "error");

e.printStackTrace();

}

}

%>

function onload(){

var flag = '';

alert(flag);

if(flag == 'error')

{

window.returnValue=flag;

window.close();

}

else if (flag == 'save')

{

window.returnValue=flag;

window.close();

}

}

function onsubmit(){

//document.getElementById("save").doflag.value='save';

document.getElementById("save").submit();

return false;

}

function oncancel(){

window.returnValue="cancel";

window.close();

}

//全选

function doallcheck(){

var allche = document.getElementById("allid");

var che = document.getElementsByName("mycheckbox");

if(allche.checked == true){

for(var i=0;i

che[i].checked="checked";

}

}else{

for(var i=0;i

che[i].checked=false;

}

}

}

function doclickcheck(obj) {

if(obj.checked==false){

var allche = document.getElementById("allid");

allche.checked = false;

}

}

我的订单

orderIdnameaddress

if(null != orderDetailList && orderDetailList.size() != 0) {

for(OrderDetail orderDetail : orderDetailList) {

%>

if(orderDetail.getFlag() == 1) {

%>

} else if(orderDetail.getFlag() == 0) {

%>

}

%>

}

}

%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值