2015-11-12 110 views
1

我无法让这段代码在Internet Explorer 11上工作。我知道这个段引发了这个问题。如果我使用此代码上传我的文件,则IE 11会将我网站的所有部分完全空白。没有它,它会显示在我的网站上的信息,但它显然不起作用。IE 11 addClass + removeClass

我查到了http://caniuse.com/上的各种功能,根据它,只有部分支持removeClass和addClass,这可能是问题所在。有没有某种插件或不同的命令,使其与IE 11兼容?

$(window).on('hashchange', function() { 
    var ImageContainer = $('.tabs > div'), 
    hash = window.location.hash !== '' ? window.location.hash: '#about'; 

    console.log(hash); 

    ImageContainer.hide(); 
    ImageContainer.filter(hash).show(); 
    $('<img/>').removeClass('selected'); 
    $('a[href="' + hash + '"]', '.ImageContainer').addClass('selected'); 
}).trigger('hashchange'); 

编辑 - MARKUP

<div class="tabs"> 

<div id="about">  
<h3>Headline</h3> 
<p>Body Text</p> 
</div> 

<div id="first"> 
<h3>Different Headline</h3> 
<p>Different Body Copy</p> 
</div> 

</div> 

<div id="owl-demo" class="owl-carousel owl-theme"> 

<div class="ImageContainer"> 
    <div id="Color"> 
    <h2>Headline</h2> 
</div> 

<div class="photo grow"> 
    <a href="#first" id="1">  
    <img src="" /> 
    </a> 
    </div> 

<div class="ImageFooter" id="Purple"> 
    <p class="ImageContainerP">Below Text</p> 
    </div> 
    </div> 

</div> 
+0

http://caniuse.com并未提供有关浏览器支持jQuery的信息,可以在[jQuery](https://jquery.com/browser-support/) –

+0

找到“我已查找过各种http://caniuse.com/_上的jquery命令“Oo-jQuery方法不是网站的一部分,因为该网站只列出本地功能。 – Andreas

+0

@GeorgeLee感谢您的指导。我会研究这一点。 –

回答

1

的问题是在IE如何对待哈希值。它不像其他浏览器那样默认为空字符串,它默认为'#'。而不是设置散列,你应该在IE中设置可靠性的位置。

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

成为

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

的标记没有被渲染,因为它没有重新上项的哈希,并给予一个错误消息“#”是不是过滤器的有效选择。

+0

你是救命恩人!非常感谢! –

2

你应该用正确的选择:

对于这个HTML:

<div class="ImageContainer"> 
    <a href="#1234"><img class="selected" src="" /></a> 
</div> 

JS:

$('img').removeClass('selected'); 
$('a[href="#1234"]', '.ImageContainer').addClass('selected'); 

OUTPUT:

<div class="ImageContainer"> 
    <a href="#1234" class="selected"><img src="" class=""></a> 
</div> 

在测试了IE 11和FF 42:

的jsfiddle:http://jsfiddle.net/ghorg12110/h1xtty4n/

+0

感谢您的帮助。不幸的是,这并没有解决我的问题,但有助于缩小搜索范围。我的问题可能隐藏在CSS或源代码的某处。这在我自己的小提琴中适用于我:http://jsfiddle.net/cef1ydna/再次感谢! –