2016-01-21 33 views
0

如何隐藏选择标记。当我试图隐藏在选择我仍然可以看到它在我的PHP页面不知道为什么?输入标签很容易隐藏,但选择的选项是难以掩饰如何隐藏,预设和禁用选择标记

<select type="hidden" style="text-color:white;"name="syearid" class="select2_group form-control" style="text-align:center;" > 

       <?php 
       $YearNow=Date('Y'); 
         include('../connection/connect.php'); 
         $result = $db->prepare("SELECT * FROM school_year"); 
         $result->bindParam(':syearid', $res); 
         $result->execute(); 
          for ($i=0; $row = $result->fetch(); $i++) { 
           $isSelected = (($YearNow=Date('Y') == $row['from_year']) ? " selected" : ""); 
           echo "<option style='text-color:white;' value='".$row['syearid']."'$isSelected>".$row['from_year'].'-'.$row['to_year']."</option>"; 
                 } 
           ?> 

           </select> 
+2

首先,你没有用'bindParam(':syearid'' –

+0

做任何事情,这不是一个'css'问题吗?答案将是'display:none;'......或'visibility:hidden' ......或者一些选项。 'select'没有'type'属性。 https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select – chris85

回答

2
<select name="syearid" class="select2_group form-control" style="text-align:center;text-color:white;display:none;" > 

display:none;将隐藏选择标签。

请注意,您也可以做到这一点(更好):

<style> 
    #syearid{text-align:center;text-color:white;display:none;} 
</style> 
<select id="syearid" name="syearid" class="select2_group form-control" > 

要预先设定的值,禁用该控件,你可以这样做:

<select disabled> 
    <option>Car</option> 
    <option selected>Bus</option> 
    <option>Van</option> 
</select> 

jsFiddle Demo

+0

如果我希望选项标签是只读的,该怎么办? – miming