有关javascript 获取checkbox复选框的实例数不胜数,下面的这个示例,纯js实现的
view sourceprint?
01 var form = document.getElementById("form2");
02
03 var field = form.elements["test2"];
04 var option = Dining.getSelectedOption(form, field);
05 var message = "";
06 for (var i = 0, len = option.length; i < len; i++) {
07 message += "Select id:" + option[i].id + "\nSelected name:" + option[i].name + "\nSelected value:" + option[i].value + "\n\n";
08 }
09 alert(message);
10 /*获取选中的选项*/
11 getSelectedOption: function (selectform, selectionfield) {
12 var result = [];
13 var option = null;
14 for (var i = 0; i < selectionfield.length; i++) {
15 option = selectionfield[i];
16 if (option.checked) {
17 result.push(option);
18 }
19
20 }
21 return result;
22
23 }
24 <form id='form2'>
25
26 <label>排序:</label><input id='aaaaa' type='checkbox' name='test2' value='1'>
27
28 <label for='aaaaa'>月销量</label><input id='bbbbb' type='checkbox' name='test2' value='2'>
29
30 <label for='bbbbb'>评分</label><input id='ccccc' type='checkbox' name='test2' value='3'>
31
32 <label for='ccccc'>优惠</label> <br style='clear:both'><label>分类:</label><input id='ddddd' type='checkbox' name='test2' value='4'>
33
34 <label for='ddddd'>商务套餐</label><input id='eeeee' type='checkbox' name='test2' value='5'>
35
36 <label for='eeeee'>凉菜</label><input id='fffff' type='checkbox' name='test2' value='6'>
37
38 </form>",
中国足彩网信息请查看IT技术专栏