0

下面的这个选择框在提交表单后会记住并突出显示 -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>
4

3 回答 3

2

$_GET['no_way']仅处理您必须使用的单个参数$_GET['no_way[]']in_array($option, $no_way)

于 2012-05-20T14:42:51.770 回答
0

我不确定这是否会有所帮助,但是您有没有机会尝试过使用selected而不是selected="selected"

<option <?php if ($no_way == $option) { ?> selected<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option>
于 2012-05-20T14:42:42.027 回答
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>
于 2012-05-20T14:46:45.287 回答