How to fix IE select issue when dynamically changing options

前端 未结 13 555
南旧
南旧 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 17:03

    I experienced the same issue the other night and after throwing everything I could think of at it I've come to the conclusion that IE just doesn't want to handle updating filters when using selects.

    My solution is to change your selects to look like this:

     
    

    They now have a class and an ng-change on them. Then in your controller do this fun little bit of code:

    $scope.fixIE = function(){
        //code to check if IE so the other browsers don't get this ugly hack.
        var selectLists = document.querySelectorAll(".selectList");
        for(var x = 0;x  < selectLists.length; x++){
            selectLists[x].parentNode.insertBefore(selectLists[x], selectLists[x]);
        }       
    };
    

    What it does is rip the elements out of the DOM and replace them into the same location. Here's a working fiddle jsFiddle

    Some of the other solutions I tried that didn't involve javascript were things like toggling the display/visibility of the select. Having their zIndex's moved. The only thing that for sure fixed it was this piece of code.

提交回复
热议问题