我有这种 jQuery:
var currentPageName = document.location.href.match(/[^\/]+$/)[0];
$("div#navigation-container nav.main-navigation ul li a").each(function () {
var link = $(this).attr("href");
if (link.contains(currentPageName)) {
$(this).addClass("active");
$(this).css("color", "white");
}
})'
它获取当前 url 和广告来导航一些事件的 css 类,它在 Firefox 中工作正常,但在 Chrome 中,我无法让它工作? 有什么解决办法吗?
最佳答案
Chrome 不支持 String.prototype.contains - Firefox 从版本 18 开始支持它。使用 indexOf相反:
if (link.indexOf(currentPageName) > -1) {
$(this).addClass("active");
$(this).css("color", "white");
}
关于jquery - AddClass 在 Firefox 中有效吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22146835/