这样定义两个复选框:
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1"checked>
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2"checked>
怎样取得它们的value值?
我试过这种取法:$_POST['xuanze'][0],$_POST['xuanze'][1],结果失败了,请问谁知道怎么取得?
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1"checked>
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2"checked>
怎样取得它们的value值?
我试过这种取法:$_POST['xuanze'][0],$_POST['xuanze'][1],结果失败了,请问谁知道怎么取得?
print_r($_POST); #看其中打印的结果
#应该是这样的:
echo $_POST['xuanze0'];
echo $_POST['xuanze1'];
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;utf-8" />
</head>
<body>
<form action="index.php" method="post">
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked />
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked />
<input type="submit" value="submit" />
</form>
</body>
</html>
[User:root Time:04:06:51 Path:/home/apache/web]$ cat index.php
<?php
print_r($_POST['xuanze']);
?>
Array ( [0] => 1 [1] => 2 )
if(isset($_POST)){
print_r($_POST);
#Array ( [id] => Array ( [0] => 3 [1] => 4 ) [del] => 删除 )
#也就是说,name中[]会被解析为0,1……
#$_POST['id'][0] => 3
}
?><form id="form3" name="form3" method="post" action="test18.php">
<p>
<label for="id2">删除序号为</label>
<input name="id[]" type="text" id="id2" size="10" value="3" />
<input name="id[]" type="text" id="id2" size="10" value="3" />
的记录
</p>
<p>
<input type="submit" name="del" id="del" value="删除" />
</p>
</form>
print_r($_POST['xuanze']眼睛瞪大!!!!!!
#test18.php
if(isset($_POST)){
print_r($_POST); #将这里打印出来看看
#Array ( [xuanze] => Array ( [0] => 1 [1] => 2 ) [del] => submit )
}
?>
<form id="form3" name="form3" method="post" action="test18.php">
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked>
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked>
<input type="submit" name="del" id="del" value="submit" />
</form>
function ccc(){
var href = "test18.php";
//这里处理参数
var param1 = "a=1";
var param2 = "b=c";
//这里将参数添加到url中
document.form3.action=href+"?&"+param1+"&"+param2;
document.form3.submit();
}
</script>
<form id="form3" name="form3" method="post" action="">
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="1" checked>
<input type="checkbox" name="xuanze[]" id="xuanze[]" value="2" checked>
<input type="button" name="del" id="del" value="submit" onclick="ccc()" />
</form>