【问题标题】:Select problems in IE9 - in other browsers it works perfectly选择 IE9 中的问题 - 在其他浏览器中它可以完美运行
【发布时间】:2015-10-01 14:25:40
【问题描述】:

我对这个特定的表格有问题,我需要先选择一个值,然后提交表格。提交表单效果很好,但是选择了所有浏览器中的默认选择值并且它是可接受的,除了在没有选择默认选择值的 IE 中。在 IE 中默认没有选择任何内容。

我该如何解决这个问题?

问题图片:

  <select name="formQuality" id="formQuality"  value="acceptable">
  <option  value="acceptable">Acceptable</option> 
  <option  value="good">Good</option>
  <option     value="better">Better</option>
  <option    value="excellent">Excellent</option>
  <option    value="best">Best</option>
  </select> 

<?php  
if(isset($_POST['SubmitButton'])){ //check if form was submitted
$input = $_POST['inputText']; //get input text
$varQuality = $_POST['formQuality'];
$message = "Success! You entered: ".$input;
}    
?>

<br>   
<form action="" method="post">
  <h1>Choose Quality:</h1>
  
  <?php 
      $thequa = htmlspecialchars($_POST['formQuality']);						  
  ?>
  
  <select name="formQuality" id="formQuality"  value="<?php echo $thequa;?>">
  <option <?php if ($thequa1 == 'acceptable') { ?>selected="true" <?php }; ?> value="acceptable">Acceptable</option>
  <option selected="true" value="acceptable">Acceptable</option>  
  <option <?php if ($_POST['formQuality'] == 'good') { ?>selected="true" <?php }; ?> value="good">Good</option>
  <option  <?php if ($_POST['formQuality'] == 'better') { ?>selected="true" <?php }; ?>   value="better">Better</option>
  <option  <?php if ($_POST['formQuality'] == 'excelent') { ?>selected="true" <?php }; ?>  value="excellent">Excellent</option>
  <option  <?php if ($_POST['formQuality'] == 'best') { ?>selected="true" <?php }; ?>  value="best">Best</option>
  </select> 
 
  <textarea name="inputText" cols="100" rows="20" style="border:solid 1px orange;"><?php echo $thetext;?></textarea> 
  <p>
  <input type="submit" value="Rewrite" name="SubmitButton"/>
 
</form> 

【问题讨论】:

  • 如果您对浏览器有疑问,最好发布浏览器获取的实际标记,而不是生成它的服务器代码。 selected 属性是布尔值,它不需要值。在 XHTML 中,它被赋予“selected”值,但只是为了满足 XML 的要求,而不是因为它实际上是必需的。
  • 好的,我这样做了,它在 stackoverflow 的测试位上运行良好,而不是在 IE 中。

标签: javascript php html internet-explorer internet-explorer-9


【解决方案1】:

预选选项的预期方法是在选项元素上设置selected 属性,而不是在选择字段中添加value 属性。

<select name="formQuality" id="formQuality">
<option value="acceptable" selected>Acceptable</option> 
<option value="good">Good</option>
<option value="better">Better</option>
<option value="excellent">Excellent</option>
<option value="best">Best</option>
</select> 

这会在所有浏览器中产生预期的结果,包括 IE。

【讨论】:

    【解决方案2】:

    使用 selected="selected" 喜欢,

    <option value="My Default" selected="selected">
    

    将选项设为默认选定值。这适用于所有浏览器。

    【讨论】:

      猜你喜欢
      • 2012-03-30
      • 1970-01-01
      • 2011-03-23
      • 2012-02-07
      • 2014-02-22
      • 2022-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多