以下脚本可让用户在on和off之间进行选择。问题是刷新页面后所选值不会保持选中状态。知道如何解决这个问题吗?
<form action="Conf.php" name="Calculation" method="post">
<?php
if (isset($_POST['Submit1']))
{
$Wave = $_POST['WaveHMap'];
}
?>
<?php
$attr = 'selected="selected"';
?>
Wave Height Maps:
<select selected="selected" name="WaveHMap" VALUE="<?PHP print $Wave ; ?>">
<?php $attr= 'selected="selected"'; ?>
<option VALUE="On"<?php echo $Wave == 'On' ? $attr : ''; ?>>On</option>
<option VALUE="Off"<?php echo $Wave== 'Off' ? $attr : ''; ?>>off</option>
</select>
<Input Type="Submit" Name="Submit1" Value="Save Parameters">
</form>
答案 0 :(得分:0)
试试这个
<select name="WaveHMap" >
<option VALUE="On" <?php echo $Wave == 'On' ? 'selected' : ''; ?>>On</option>
<option VALUE="Off" <?php echo $Wave== 'Off' ? 'selected': ''; ?>>off</option>
</select>