传递checkbox多选到php不用数组的方法
一般都是用数组的方法,name=business_type[]
不过使用数组的时候不好判断是否必填
本例一段简单的js代码,传递一个参数
XML/HTML Code
- <form action="send.php" method="post">
- <input type="hidden" name="tempString" id="tempString" value="">
- <input type="checkbox" id="business_type" value="1" name="business_type" class="checkbox"/>
- 1<Br />
- <input type="checkbox" id="business_type" value="2" name="business_type" class="checkbox"/>
- 2<Br />
- <input type="checkbox" id="business_type" value="3" name="business_type" class="checkbox"/>
- 3<Br />
- <input type="submit" onclick="aa();">
- </form>
- <script>
- function aa() {
- var bb = "";
- var temp = "";
- var a = document.getElementsByName("business_type");
- for ( var i = 0; i < a.length; i++) {
- if (a[i].checked) {
- temp = a[i].value;
- bbbb = bb + "," +temp;
- }
- }
- document.getElementById("tempString").value = bb
- .substring(1, bb.length);
- }
- </script>
原文地址:http://www.freejs.net/article_biaodan_588.html