IE 11 addClass + removeClass

前端 未结 2 597
我在风中等你
我在风中等你 2021-01-25 01:49

I can not get this code to work on Internet Explorer 11. I know this segment is causing the problem. If I upload my file with this code active, IE 11 dispays entire sections of

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-25 02:30

    The issue is on how IE treats hash. It doesn't default to empty string like the other browsers, it defaults to '#'. Also rather than setting hash, you should set location for reliability in IE.

    hash = window.location.hash !== '' ? window.location.hash: '#about';
    

    becomes

    hash = window.location.hash;
    if (hash !== '' || hash !== '#') {
       hash = '#about';
       window.location = hash;
    }
    

    The markup was not rendering because it was not resetting the hash on entry and giving an error message that '#' was not a valid selector for the filter.

提交回复
热议问题