chckbox多选
1、HTML结构
< 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 = "fun()" /> |
2、javascript代码
1
2
3
4
5
6
7
8
9
|
function fun(){ obj = document.getElementsByName( "test" ); check_val = []; for (k in obj){ if (obj[k].checked) check_val.push(obj[k].value); } alert(check_val); } |