我需要选择用户在多选菜单中选择的选项.这是我到目前为止的代码,但仍然不起作用.谢谢您的帮助!
<select name="cb_estatura2[]" size="6" multiple="multiple" class="inputbox" id="cb_estatura2">
<?php
$height = array("57","58","59","60");
$choosen_height = $_GET['cb_estatura2'];
for ($i=0;$i<count($height);$i++)
{
$selected = ($height[$i] == $choosen_height[$i] ? 'selected="selected"' : '');
echo "<option value='$height[$i]' $selected>$height[$i]</option>";
}
?>
</select>
Run Code Online (Sandbox Code Playgroud)
应该工作的一件事是:
<select name="cb_estatura2[]" size="6" multiple="multiple" class="inputbox" id="cb_estatura2">
<?php
$height = array("57","58","59","60");
$choosen_height = $_GET['cb_estatura2'];
for ($i=0;$i<count($height);$i++)
{
$selected = (in_array($height[$i],$choosen_height) ? 'selected="selected"' : '');
echo "<option value='$height[$i]' $selected>$height[$i]</option>";
}
?>
</select>
Run Code Online (Sandbox Code Playgroud)
这应该工作,只是因为$_GET['cb_estatura2']不像$height数组那样填充.可能是错的,没有测试过.
| 归档时间: |
|
| 查看次数: |
4141 次 |
| 最近记录: |