IE 11 addClass + removeClass [英] IE 11 addClass + removeClass

查看:95
本文介绍了IE 11 addClass + removeClass的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在Internet Explorer 11上使用此代码.我知道此段引起了问题.如果我在激活该代码的情况下上传文件,则IE 11会完全忽略我网站的整个部分.没有它,它将在我的网站上显示信息,但显然功能不一样.

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 my website completely blank. Without it, it will display the information on my site, but it obviously doesn't function the same.

根据我的说法,我在 http://caniuse.com/上查找了各种功能,部分支持removeClass和addClass,这可能是问题所在.是否有某种插件或其他命令可以使其与IE 11兼容?

I have looked up various features on http://caniuse.com/, according to it, there is only partial support for removeClass and addClass, which may be the problem. Is there some sort of plugin or a different command to make this compatible with 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');   

编辑-标记

<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>

推荐答案

问题在于IE如何处理哈希.它不像其他浏览器那样默认为空字符串,而是默认为'#'.同样,除了设置哈希值之外,您还应该设置IE中可靠性的位置.

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';

成为

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.

这篇关于IE 11 addClass + removeClass的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆