jQuery IE 错误与 wordpress: 行: 3 错误: 语法错误, 无法识别的表达式: nth-of-typ



我在wordpress中构建了一个子主题。我正在使用jQuery来隐藏和显示子菜单。除IE之外,所有浏览器都运行良好。在IE中,我的jQuery都不适用于子菜单。当我尝试调试时,出现此错误。

行: 3错误:语法错误,无法识别的表达式:第 n 种类型

该错误出现在wordpress使用的内置jQuery库中。我在自己的 Jquery 中使用了第 n 种类型的选择器,但即使我删除它们,问题仍然存在。这是我用来控制子菜单的jQuery

if ($("body").hasClass('taxonomy-colordesign')){
$("#hybrid-categories-5 h4").toggleClass("tabDown");//pulls the background image in the tab
$("#hybrid-categories-5 h4").siblings('.dots').toggleClass('active');//activates the little square next to it
$("#hybrid-categories-5 h4").next("ul.xoxo.categories").toggleClass("openTab");//opens up the ul that contains the list of options
$(".menu-main-menu-container li:nth-of-type(3) a").addClass("current");
} 
else if ($("body").hasClass('taxonomy-colorart')){
$("#hybrid-categories-12 h4").toggleClass("tabDown");
$("#hybrid-categories-12 h4").siblings('.dots').toggleClass('active');
$("#hybrid-categories-12 h4").next("ul.xoxo.categories").toggleClass("openTab");
$(" #hybrid-categories-9, #hybrid-categories-3, #hybrid-categories-5").hide();
$(".menu-main-menu-container li:nth-of-type(2) a").addClass("current");
}
else if ($("body").hasClass('taxonomy-mediadesign')){
$("#hybrid-categories-3 h4").toggleClass("tabDown");
$("#hybrid-categories-3 h4").siblings('.dots').toggleClass('active');
$("#hybrid-categories-3 h4").next("ul.xoxo.categories").toggleClass("openTab");
$(".menu-main-menu-container li:nth-of-type(3) a").addClass("current");
}

如果有人能帮助我,我将不胜感激。

因为第 n 种类型不是有效的 jquery 选择器。

例如。

$(".menu-main-menu-container li:nth-of-type(2) a").addClass("current");无效,请将其更改为

 $(".menu-main-menu-container li:eq(2) a").addClass("current");

您可以参考 http://api.jquery.com/nth-child-selector/或 http://api.jquery.com/eq/以获取文档

最新更新