How to fix IE select issue when dynamically changing options

前端 未结 13 554
南旧
南旧 2020-12-04 16:38

I have a set of selects that all have the same options. Then I run those options through a filter so that any options that are selected in a different select don\'t show up

13条回答
  •  生来不讨喜
    2020-12-04 16:56

    The rendering gets updated and synched if you change some attribute. An innocuous change may be to set the selectedIndex attribute to its own value:

    function fixIEselect() {
        for (var nForm = 0; nForm < document.forms.length; ++nForm) {
            var form = document.forms[nForm];
            var children = form.children;
            for (var nChild = 0; nChild < children.length; ++nChild) {
                var child = children.item(nChild);
                if (child.tagName == "SELECT") {
                    alert("Fixed: " + child.name);
                    child.selectedIndex = child.selectedIndex; // dummy nop but not
                }
            }
        }
    }
    
    fixIEselect();
    

提交回复
热议问题