HTML代碼: js代碼: ...
HTML代碼:
<form action="/test/action" method="get"> <input type="checkbox" name="myname" value="1"/>1 <input type="checkbox" name="myname" value="2"/>2 <input type="checkbox" name="myname" value="3"/>3 <input type="checkbox" name="myname" value="4"/>4 <input type="checkbox" name="myname" value="5"/>5 <input type="button" οnclick="formSubmit()" value="提交" /> </form>
js代碼:
<script> function formSubmit() { var obj = document.getElementsByName("myname"); var check_arr = []; for (var i = 0; i < obj.length; i++) { if (obj[i].checked) check_arr.push(obj[i].value); } alert(check_arr); } </script>