多选select 的name必须是一个name_value[],后面有这个中括号,为哈?
如果不是中括号的话,你用httpfox抓下包,
select 1
select 2
select 3
php他会得到一个值,也就是多选最下面的那个值,而在加上中括号后呢,就会出现如下:
select[] 1
select[] 2
select[] 3
select.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>提交多选的静态页</title>
</head>
<body>
<form id="post_form" name="post_form" method="post" action="./select.php">
<select name="select[]" size="10" multiple="multiple" id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label> <br />
<input type="submit" name="button" id="button" value="提交" />
</label>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP接收多选是一个数组</title>
</head>
select.php
<body>
<?php
print_r($_POST['select']);
?>
</body>
</html>
这样PHP得到:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
如果不是中括号的话,你用httpfox抓下包,
select 1
select 2
select 3
php他会得到一个值,也就是多选最下面的那个值,而在加上中括号后呢,就会出现如下:
select[] 1
select[] 2
select[] 3
select.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>提交多选的静态页</title>
</head>
<body>
<form id="post_form" name="post_form" method="post" action="./select.php">
<select name="select[]" size="10" multiple="multiple" id="select">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<label> <br />
<input type="submit" name="button" id="button" value="提交" />
</label>
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP接收多选是一个数组</title>
</head>
select.php
<body>
<?php
print_r($_POST['select']);
?>
</body>
</html>
这样PHP得到:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:http://jackxiang.com/post/1828/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
评论列表