我想设置一个类来激活取决于网址。我试图使用下面的代码,但是在任何情况下,它都会激活第二个选项卡的活动类。Javascript - 如果陈述不起作用?
var pathname = window.location.pathname;
if(pathname = '/learn/subsection2') {
$("ul.tabs li:eq(1)").addClass("active").show(); //Activate second tab
$(".tab_content:eq(1)").show(); //Show second tab content
} else {
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
}
呃犯罪......这是漫长而漫长的一天... :)谢谢。 :::咧嘴笑,然后隐藏在一块岩石下::: – phpN00b 2009-11-19 00:56:37
是的,你正在分配,而不是比较路径名和字符串的值。 – putolaruan 2009-11-19 00:56:38