前台checkbox复选框提交到后台处理

前台

<input type="hidden" id="tempString" name="tempString" />

<#list resultSet as record>
<tr>
<td><input type="checkbox" name="putaway" value=${(record.id)!} /></td>
<td>${(record.merchantname)!}</td>
<td>${(record.description)!}</td>
</tr>
</#list>

JS

function morecheck() {
var bb = "";
var temp = "";
var a = document.getElementsByName("putaway");
for ( var i = 0; i < a.length; i++) {
if (a[i].checked) {
temp = a[i].value;
bb = bb + "," +temp;
}
}
document.getElementById("tempString").value = bb .substring(1, bb.length); //赋值给隐藏域
}
//上架
function upaway(){
morecheck() ;
if(confirm("确定要上架吗?")){
document.dbform.action="/merchantManage/upaway";
dbform.submit();
}
}

后台

String mId = this.getPara("tempString");
String temp[] = mId.split(",");// 截取字符串,获得各个checkBox的值
for (int i = 0; i < temp.length; i++) {
Db.update("update merchant_info set status =0 where id=" + temp[i]);
}

孔曰成仁,孟曰取义
原文地址:https://www.cnblogs.com/haorun/p/6149450.html