【发布时间】:2021-08-10 00:15:08
【问题描述】:
我希望下面的代码显示所有选中的复选框并限制为 2 个复选框。
输入
<form method="post" action="Outputofinfo.php">
<b style="font-size:19px ; color: #7a1ac4; font: Arial,tahoma,sans-serif; ">Favourite Movie Genre:</b><br>
<input type="checkbox" name="mg" value="Romance">
<label for="mg1"> Romance</label><br>
<input type="checkbox" name="mg" value="Comedy">
<label for="mg2"> Comedy</label><br>
<input type="checkbox" name="mg" value="Horror">
<label for="mg3"> Horror</label><br>
<input type="checkbox" name="mg" value="Action">
<label for="mg4"> Action</label><br>
<input type="checkbox" name="mg" value="Fiction">
<label for="mg5"> Fiction</label><br>
<input type="submit">
</form>
输出
$fmg = $_POST['mg'];
<div style ='font:21px Arial,tahoma,sans-serif;color:#7a1ac4'>
<b>Favourite Movie Genre:</b>
<?php echo $fmg; ?>
</div>
【问题讨论】:
-
使用
name="mg[]"然后$_POST["mg"]将是一个数组。必须使用 JavaScript 来限制复选框的数量