获取checkbox里选中的多个值
<input type="checkbox" name="test" value="1"/><span>1</span>
<input type="checkbox" name="test" value="2"/><span>2</span>
<input type="checkbox" name="test" value="3"/><span>3</span>
<input type="checkbox" name="test" value="4"/><span>4</span>
<input type="checkbox" name="test" value="5"/><span>5</span>
<input type='button' value='全选' onclick="setall()"/>
<input type='button' value='提交' onclick="fun()"/>
function fun(){
obj = document.getElementsByName('test');
check_val = [];
for(k in obj){
if(obj[k].checked)
check_val.push(obj[k].value);
}
return check_val;
}
checkbox全选
function setall(){
let o = document.getElementsByName('test')
for (i=0;i<o.length;i++) {
o[i].checked = event.srcElement.checked
}
}