How to set current page “active” in php

后端 未结 17 1901
栀梦
栀梦 2020-12-02 21:38

Hi I have a menu on my site on each page, I want to put it in it\'s own menu.php file but i\'m not sure how to set the class=\"active\" for whatever page i\

17条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 21:52

    A bit late on the ball, but I just had to solve this myself and ended up using this Javascript method, with a small modification. This has the advantage on not requiring many changes to the current code, just run the script and voila.

    window.onload = activateCurrentLink;
    
    function activateCurrentLink(){
        var a = document.getElementsByTagName("A");
        for(var i=0;i

提交回复
热议问题