您的位置:首页 > Web前端 > JavaScript

js获取所有复选框中的值

2015-11-01 13:48 537 查看
如果不是用的struts2中s标签的checkboxList的话,通过js获取所有复选框中的值则可用以下代码:

function next(openId){
var box = document.getElementsByName("box");
var objArray = box.length;
var chestr="";

for(var i=0;i<objArray;i++){
if(box[i].checked == true){
chestr+=box[i].value+",";
}
}
alert(chestr);
href = "${ctx }/fw/open?openId="+openId+"&chestr="+chestr;
window.showModalDialog( href,'window',"dialogHeight=600px;dialogWidth=910px;center=yes");
}


<input type="checkbox" name="box" id="box1" value="区划" />区划
<input type="checkbox" name="box" id="box2" value="邮编编码" />邮编编码
<input type="checkbox" name="box" id="box3" value="联系电话" />联系电话
......
<input type="button" name="button" id="button" onclick="checkbox()" value="下一步" />
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: