JQuery隐藏选项没有'我在IE 11中不工作

JQuery Hide Option doesn't work in IE 11

本文关键字:IE 我在 工作 选项 隐藏 JQuery      更新时间:2024-03-25

我使用此代码在IE中隐藏选项,它在除IE 11之外的所有浏览器中都能正常工作这里有隐藏和显示选项的代码

$("[id*=dllStates] option").each(function (index, val) {
            if ($(this).is('option') && (!$(this).parent().is('span')))
                $(this).wrap((navigator.appName == 'Microsoft Internet Explorer') ? '<span>' : null).hide();
        });

并显示我使用这个

var counterIE = 0;
            $("[id*=dllStates]").next().children().html("Select Supplier");
            for (i = 0; i < supplierID.length; i++) {
                $("[id*=dllStates] option").each(function (index, val) {
                    if (navigator.appName == 'Microsoft Internet Explorer') {
                        if (this.nodeName.toUpperCase() === 'OPTION') {
                            var span = $(this).parent();
                            var opt = this;
                            if ($(this).val() == supplierID[counterIE]) {
                                if ($(this).parent().is('span')) {
                                    $(opt).show();
                                    $(span).replaceWith(opt);
                                }
                            }
                        }
                    }
                });
                counterIE = counterIE + 1;
            }

为什么这在IE 11中不起作用感谢

在IE11中,navigator.appName不是'Microsoft Internet Explorer',它实际上是'Netscape'