Go homepage(回首页) Upload pictures (上传图片) Write articles (发文字帖)
The author:(作者)归海一刀published in(发表于) 2014/2/10 6:48:58 PHP开发中接收复选框信息的方法_[PHP教程]
<form name="form1" id="form1" method="post" action="myphp.php" onSubmit="return Checker()"> <input type="checkbox" name="item" value="1">1<br> <input type="checkbox" name="item" value="2">2<br> <input type="checkbox" name="item" value="3">3<br> <input type="checkbox" name="item" value="4">4<br> <input type="hidden" name="items" value=""> <input type="submit" value="Submit"> </form>
<script language="javascript"> <!-- function Checker() { form1.items.value = ""; if ( !form1.item.length ) // 只有一个复选框,form1.item.length = undefined { if ( form1.items.checked ) form1.items.value = form1.item.value; } else { for ( i = 0 ; i < form1.item.length ; i++ ) { if ( form1.item(i).checked ) // 复选框中有选中的框 { form1.items.value = form1.item(i).value; for ( j = i + 1 ; j < form1.item.length ; j++ ) { if ( form1.item(j).checked ) { form1.items.value += " "; //用空格做分割符 form1.items.value += form1.item(j).value; } } break; } } } return true; } --> </script>
items = explode(" ", HTTP_POST_VARS["items"]);
赞