HTML代码:
<html>
<head>
< >php 表单select元素多选实例</ >
</head>
<body>
<div>
<form action=\"index.php\" method=\"post\">
<p><input type=\"text\" name=\"user\" /></p>
<p><textarea name=\"address\" rows=\"5\" cols=\"40\">
</textarea></p>
<p><select name=\"products[]\" multiple=\"multiple\">
<option>A</option>
<option>B</option>
<option>C</option>
<option>D</option>
</select></p>
<p><input type=\"submit\" value=\"hit it!\" /></p>
</form>
</div>
</body>
</html>
php服务器端代码:
<html>
<head>
< >Reading Input from the Form</ >
</head>
<body>
<div>
<?php
print \"Welcome <b>\" . $_POST [\'user\'] . \"</b><br/>\";
print \"Your address is:<br/><b>\" . $_POST [\'address\'] . \"</b><br/>\\n\";
if (is_array ( $_POST [\'products\'] )) {
print \"<p>Your product choices are:</p>\";
print \"<ul>\";
foreach ( $_POST [\'products\'] as $value ) {
print \"<li>$value</li>\\n\";
}
print \"</ul>\";
}
?>
</div>
</body>
</html>
大家可以将代码部署在自己电脑上运行一下。
继续阅读与本文标签相同的文章
下一篇 :
从感知测试切入自动驾驶,这家公司做对了什么?
-
美女机器人刚上市就售罄,除了生孩子,其他什么都能干!
2026-05-14栏目: 教程
-
互联网之光大会的黑科技,总有一款惊艳你!
2026-05-14栏目: 教程
-
微信宣布一项新举措,关系到每一个用户,网友一致力挺:干得漂亮!
2026-05-14栏目: 教程
-
微软建议企业客户卸载KB4520062累积更新
2026-05-14栏目: 教程
-
他让我国芯片研究停滞13年,还骗走11亿研发资金,现状如何?
2026-05-14栏目: 教程
