2014-03-03 22 views
0

我有这样的jQuery:AddClass在Firefox中使用?

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中,我无法得到它的工作? 任何解决方案? -

+0

提供你的HTML –

+0

它工作在mozzila好,我觉得问题是与document.location? – Schneider

+0

Chrome不支持'String.prototype.contains':https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/contains - Firefox从版本18开始支持它。 [indexOf](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf)而不是 – CodingIntrigue

回答