2012-02-03 26 views
0

我想用jquery隱藏一些<options>標籤,但它似乎並不工作。試圖隱藏jQuery的一些選項標籤不起作用IE,Safari和Opera

  • 我想隱藏所有具有rel屬性的選項。

  • 只顯示rel='3'

此代碼的選項適用於FF和Chrome。無法使用IE,Safari和Opera。

這裏是我的jsfiddle:

http://jsfiddle.net/RnfqW/4/

這裏是標記和腳本:

<select name="myselect" id="myselect" > 
    <option value=''></option> 
    <option rel='1' value='1A'>1A</option> 
    <option rel='1' value='1B'>1B</option> 
    <option rel='2' value='2A'>2A</option> 
    <option rel='2' value='2B'>2B</option> 
    <option rel='2' value='2C'>2C</option> 
    <option rel='3' value='3A'>3A</option> 
    <option rel='3' value='3B'>3B</option> 
    <option rel='3' value='3C'>3C</option> 
    <option rel='3' value='3D'>3D</option> 
</select> 

腳本:

$("#myselect [rel]").hide(); // hide all options 
$("#myselect [rel=3]").show(); // hide whow only rel=3 options 
+0

的可能重複[刪除作品,但不能掩蓋?](http://stackoverflow.com/questions/3309787/remove-works-but-not-hide) – 2012-02-03 13:12:29

+0

請參閱以下[問題](http://stackoverflow.com/questions/2324250/style-display-none-doesnt-work-on-option-tags-in-chrome-but-it-does-in-firefo) 。它解決了。 – Oybek 2012-02-03 13:17:19

+1

移除的問題是您無法重新創建它。 – 2012-02-03 13:22:04

回答

1

您CA不隱藏或顯示選項。你必須做的是克隆你不想要的選擇和刪除選項標籤。

編輯:這樣的事情http://jsfiddle.net/RnfqW/5/

0

看看這個代碼,並對其進行自定義。我希望這將是有益的......

$(function(){ 
    $.fn.extend({ 
     slidingSelect: function(options) 
     { 
      var select= $(this); 
      var selector=select.selector; 
      var selectedValue="";//=select.val(); 

      var divToggle=$("<div>"+selectedValue+"select Complaint<span style='float:right;'>&#x25BC;</span></div>").attr({id:select.attr("id")+"Toggle"}).click(function(){ 
       $(selector).slideToggle(); 
      }).insertBefore(select); 

      select.attr("size",6); 
      select.change(function(){ 
       divToggle.html(select.val()+"<span style='float:right;'>&#x25BC;</span>"); 
       $(selector).slideToggle(); 
      }); 

     }  
    }); 
    $("#complaint").hide().slidingSelect(); 

}); 
相關問題