How do I highlight a link based on the current page?

后端 未结 7 548
日久生厌
日久生厌 2020-12-30 08:21

Sorry if this sounds like a really stupid question, but I need to make a link change colour when you are on the page it links to.

For example, when you are on the \"

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-30 08:39

    If for some reason you don't want to handle this on the server-side, you can try this:

    // assuming this JS function is called when page loads
    onload()
    {
      if (location.href.indexOf('/questions') > 0)
      {
        document.getElementById('questionsLink').className = 'questionsStyleOn';
      }
    }
    

提交回复
热议问题