Javascript - if语句不工作? [英] Javascript - if statement not working?

查看:99
本文介绍了Javascript - if语句不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据网址将类设置为活动。我试图使用下面的代码,但在任何情况下,它激活第二个选项卡的活动类。

I'm trying to set a class to active depending on the url. I'm trying to use the code below, but in every case, it activates the active class for the second tab.

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
    }


推荐答案

if(pathname == '/learn/subsection2') {
...

这篇关于Javascript - if语句不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆