后提交表单上强调了多选(Highlighting multiple selections on a

2019-10-16 17:37发布

下面这个选择框并记住并提交表单后突出 - 酮的选择。 但是,当我让它多,它不提交后突出任意选择的结果。 关于如何实现这一目标的任何想法?

提前致谢。

<?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>

Answer 1:

这对我的作品:

<?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>


Answer 2:

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



Answer 3:

我不知道这是否会帮助或没有,但有你试过只使用任何机会selected ,而不是selected="selected"

<option <?php if ($no_way == $option) { ?> selected<?php }?> value="<?php echo $option; ?>"><?php echo $option; ?></option>


文章来源: Highlighting multiple selections on a form after submitting