简体   繁体   English

在IE浏览器上选择下拉显示隐藏(添加删除元素)

[英]Select drop down show hide (add remove element)on I.E Browser

I have select dropdown i have 2 different shipping methods available in that dropdown. 我选择下拉菜单,在该下拉菜单中有2种不同的送货方式。 If i select sipping 1 i want to hide the Rest fexex shipping options & vice versa if i selected any of the fedex method i want to hide freeshipping 如果我选择饮1,我想隐藏其余fexex的运输选项,反之亦然,如果我选择了任何联邦快递方法,我想隐藏免运费

please check js fiddle below 请检查下面的js小提琴

<fieldset>
   <select name="shipping_method" id="shipping_method" style="width:250px;" class="required-entry">
      <option value="">Please select a shipping method...</option>
      <optgroup label="Free Shipping" style="font-style:normal;">
         <option value="freeshipping_freeshipping">
            Shipping1 - $0.00                                                    
         </option>
      </optgroup>
      <optgroup label="FedEx" style="font-style:normal;">
         <option value="fedex_FEDEX_GROUND">
             Fedex1 - $18.07                                                    
         </option>
         <option value="fedex_FEDEX_2_DAY">
             Fedex2 - $30.62                                                    
         </option>
         <option value="fedex_STANDARD_OVERNIGHT">
             Fedex3 - $81.34                                                    
         </option>
      </optgroup>
   </select>
</fieldset>
<a href="#" class="shipping-reset" style="display: none">Clear Shipping Selection</a>
<p class="actions">
   <button id="update_shipping_method_submit" type="submit" class="button" style="display: none;"><span><span>Update Shipping Method</span></span></button>
</p>

jsfiddle jsfiddle

Try something like this(not tested) 尝试这样的事情(未测试)

$('select').on('change', function() {
var arr1 = $('#shipping_method option:not(:selected)');
    for (var i = 0; i < arr1.length; i++) {
        $("#shipping_method").children("optgroup[label='" + arr1[i].value + "']").remove();
        console.log("removed");
        }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM