Jquery IE 11 addClass+;移除类
我无法在Internet Explorer 11上使用此代码。我知道这部分是造成问题的原因。如果我上传我的文件并激活此代码,即11显示我网站的整个部分完全空白。如果没有它,它将在我的网站上显示信息,但显然它的功能不同 我在上查看了各种功能,根据它的说法,只有部分支持removeClass和addClass,这可能是问题所在。是否有某种插件或其他命令使其与IE11兼容Jquery IE 11 addClass+;移除类,jquery,internet-explorer,Jquery,Internet Explorer,我无法在Internet Explorer 11上使用此代码。我知道这部分是造成问题的原因。如果我上传我的文件并激活此代码,即11显示我网站的整个部分完全空白。如果没有它,它将在我的网站上显示信息,但显然它的功能不同 我在上查看了各种功能,根据它的说法,只有部分支持removeClass和addClass,这可能是问题所在。是否有某种插件或其他命令使其与IE11兼容 $(window).on('hashchange', function () { var ImageContainer =
$(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');
$(窗口).on('hashchange',函数(){
var ImageContainer=$('.tabs>div'),
hash=window.location.hash!=''?window.location.hash:'关于';
console.log(散列);
ImageContainer.hide();
ImageContainer.filter(hash.show();
$('').removeClass('selected');
$('a[href=“'+hash+'”],'.ImageContainer').addClass('selected');
}).trigger(“hashchange”);
编辑标记
大字标题
正文
不同的标题
不同的正文副本
大字标题
以下文本
您应该使用正确的选择器:
对于此HTML:
<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>
输出:
$('img').removeClass('selected');
$('a[href="#1234"]', '.ImageContainer').addClass('selected');
在IE 11和FF 42上测试:
jsfiddle:问题在于IE如何处理哈希。它不像其他浏览器那样默认为空字符串,而是默认为“#”。此外,您还应该在IE中为可靠性设置位置,而不是设置哈希
<div class="ImageContainer">
<a href="#1234" class="selected"><img src="" class=""></a>
</div>
变成
hash = window.location.hash !== '' ? window.location.hash: '#about';
标记未呈现,因为它未重置条目上的哈希值,并给出一条错误消息,指出“#”不是筛选器的有效选择器。未提供有关浏览器对jQuery支持的信息,请参见“我已在上查找了各种jQuery命令”O.O-jQuery方法不是网站的一部分,因为网站只列出本机功能。@GeorgeLee感谢您的指导。我会调查的。谢谢你的帮助。不幸的是,这并没有解决我的问题,但有助于缩小搜索范围。我的问题可能隐藏在CSS或源代码中。这对我来说很管用:再次感谢!你是救命恩人!非常感谢你!
hash = window.location.hash !== '' ? window.location.hash: '#about';
hash = window.location.hash;
if (hash !== '' || hash !== '#') {
hash = '#about';
window.location = hash;
}