checkbox传多个值问题:
test.jsp页面:
<script type="text/javascript">
function chkChxTest(){
//检查是否选中
var c = document.getElementsByName("chkbox");
var v_flag = false;
for(var i=0;i<c.length;i++) {
if(c[i].checked) {
v_flag = true;
//alert(""+c[i].id);
break;
}
}
//获得选中的checkbox拼装成的batchItemCode字符串
var batchItemCode = '';
var batchProductName = '';
if(v_flag==true){
//拼成批量要删除的编号itemCode
for(var i=0;i<c.length;i++) {
if(c[i].checked) {
batchItemCode += c[i].id+',';
batchProductName += c[i].value+',';
}
}
}else{
alert('请选取一个复选框!');
return;
}
//删除最后一个,
//batchItemCode = removeLastCharStr(batchItemCode);
// batchProductName = removeLastCharStr(batchProductName);
alert('batchItemCode的值等于'+batchItemCode);
alert('batchProductName的值等于'+batchProductName);
}
</script>
<input id="001=E350" type="checkbox" name="chkbox" value="A0"/>A0 <br/>
<input id="002=E351" type="checkbox" name="chkbox" value="A1"/>A1 <br/>
<input id="003=E352" type="checkbox" name="chkbox" value="A2"/>A2 <br/>
<input id="btnid" type="button" name="btn" οnclick="chkChxTest()" value="测试chkbox"/>
2. Java类解析checkbox获得的多个值
String itemStr = "001=E351,002=E352,003=E353,004=E354";
String[] itemStrArr = itemStr.split(",");
String[] itemStrArr0 = new String[itemStrArr.length];
String[] itemStrArr1 = new String[itemStrArr.length];
for(int i=0; i<itemStrArr.length; i++){
String temp = itemStrArr[i];
String[] itempsplit = temp.split("=");
itemStrArr0[i]= itempsplit[0];
itemStrArr1[i]= itempsplit[1];
}
for(String str0: itemStrArr0){
System.out.println(str0);
}
for(String str1: itemStrArr1){
System.out.println(str1);
}