1,JS方式(通用!)
<html><head><title>测试页面</title>
</head>
<body>
<form act
请选择:
<input type="checkbox" value="值1" name="chb">测试1
<input type="checkbox" value="值2" name="chb">测试2
<input type="checkbox" value="值3"name="chb">测试3<br>
<input type="hidden" name="chbvalue">
<input type="submit" value="提交" on
</form>
<?php
if(null!=$_POST["chbvalue"]){
$chbvalue=$_POST["chbvalue"];
$arrvalue=explode(",",$chbvalue); //分割隐藏域的值
echo "选中值为:";
foreach($arrvalue as $v){
echo $v."/t";
}
}
?>
</body>
<script language="javas
function getvalue(){
var chb=document.getElementsByName("chb"); //注意复选框的name属性都相同
var chbvalue=document.getElementById("chbvalue");
for(i=0;i<chb.length;i++){
if(chb[i].checked)
chbvalue.value+=chb[i].value+","; //设置隐藏域的值为复选框的值+,
}
}
</script>
</html>
2,数组方式
<html><head><title>测试页面</title>
</head>
<body>
<form act
请选择:
<input type="checkbox" value="值1" name="chb[]">测试1
<input type="checkbox" value="值2" name="chb[]">测试2
<input type="checkbox" value="值3"name="chb[]">测试3<br>
<input type="hidden" name="chbvalue">
<input type="submit" value="提交" on
</form>
<?php
if(null!=$_POST["chb"]){
$chb=$_POST["chb"]; //注意复选框name属性为数组
foreach($chb as $v){
echo $v."/t";
}
}
?>
</body>
</html>