下面的这个选择框会在提交表单后记住并突出显示-one-选择。但是,当我将其设为多个时,它在提交后不会突出显示任何选项。 有关如何实现这一点的任何想法?
提前致谢。
<?php
$options_amount = array("0","1","2","3","4","5","6","7","8","9","10+");
$no_way = $_GET['no_way'];
?>
<select class="postform" name="no_way[]" multiple size="5">
<option <?php if ($no_way == 'all') { ?>selected="selected"<?php }?> value="all">Any</option>
<?php
foreach ($options_amount as $option) {
?><option <?php if ($no_way == $option) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php }?>
</select>
答案 0 :(得分:2)
$_GET['no_way']
仅处理您必须使用$_GET['no_way[]']
和in_array($option, $no_way)
答案 1 :(得分:0)
我不确定这是否有帮助,但您是否有可能尝试使用selected
代替selected="selected"
?
<option <?php if ($no_way == $option) { ?> selected<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option>
答案 2 :(得分:0)
这对我有用:
<?php
$options_amount = array("0","1","2","3","4","5","6","7","8","9","10+");
$no_way = $_GET['no_way'];
?>
<select class="postform" name="no_way[]" multiple size="5">
<option <?php if (in_array("all",$no_way)) { ?>selected="selected"<?php }?> value="all">Any</option>
<?php
foreach ($options_amount as $option) {
?><option <?php if (in_array($option,$no_way)) { ?>selected="selected"<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option><?php }?>
</select>