Javascript - if statement not working?

前端 未结 5 987
生来不讨喜
生来不讨喜 2021-01-25 15:02

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.

<         


        
5条回答
  •  甜味超标
    2021-01-25 15:53

    You used a = instead of a == or === in your comparison. This is why many programmers shift the statement around so it throws an error vs. running code unintentionally... its a very common mistake!

    Here is an example of the same ifg statement switched around. Had you used this format, but made the same mistake, it would have thrown an error which would have helped you located it faster:

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

提交回复
热议问题