Options with display:none not hidden in IE

后端 未结 10 1049
梦如初夏
梦如初夏 2020-11-27 17:41

I have multiple options in a select. I have sorted the options and disabled and hidden the duplicate options with jquery. The code works well in chrome and firefox but in IE

10条回答
  •  一个人的身影
    2020-11-27 18:32

    my 2 cents worth on an "old question", yet still a relevant issue.

    Server side:

    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)
       { //load subDropDownList all possible values [with an attribute for filtering] }
    }
    

    Client-side:

    var optionList = null;
    $(function(){
      if (!optionList)
      {
         optionList = new Array();
         $("[id$='subDropDownList'] option").each(function () {
             optionList.push({value: $(this).val(), text: $(this).text(), filterID: $(this).data("filterid") }); 
          });
      } 
    
      $("[id$='mainDropDownList']").on("change", function (e) {
         var filterID = $(this).val();
         $("[id$='subDropDownList']").html("");
    
         $.each(optionList, function () {
            if (this.filterID == filterID)
              $("[id$='subDropDownList']").append($("").val(this.value).html(this.text).data("filterid", this.filterID));
            });
    
    
      });
    
    })
    

    The idea here is on client side I load all values into an array, then on change event of the main select I add only the required options. Hope someone finds this helpful.

提交回复
热议问题