The style of the navigation bar


< div class="cssmenu" >

        <ul>
            <li class="active"><a href="index.jsp"><span></span></a></li>
            <li><a href="recommend.jsp"><span></span></a></li>
            <li><a href="staff.html"><span></span></a></li>
            <li><a href="contact.html"><span></span></a></li>
             <div class="clear"></div>
         </ul>

< / div >

there is a navigation bar like this. How do you want to activate the class="active" style according to the hyperlink you click?

clicking the navigation bar will jump to the corresponding page. Can I still use js?

Click the home page, the home page will have a red background, and jump to the home page

Click on the popular book, which will have a red background and jump to the page of the popular book

Feb.24,2022

var li = document.querySelectorAll('li');
for(var i = 0,len = li.length;li < len;iPP){
      li[i].index = i;
      li[i].onclick = function(){
         for(var _i = 0,_len = li.length;_i < _len;_iPP){
            if(_i === this.index){
                li[_i].className = 'active';//li[_i].classList.add('active')
            }else{
               li[_i].className="";//li[_i].classList.remove('active');
            }
         }
      }

}

var ulList = document.getElementById ('ul-list')

var liList = document.getElementsByTagName('li');
for(var i=0; i<liList.length; iPP){
    liList[i].addEventListener('click',function(){
        for(var j=0; j<liList.length; jPP){
            liList[j].classList.remove('active')
        }
        this.classList.add('active');             
    },false)
}

For

dexterity, consider : target this css3 selector. Add an anchor to the new page, and then use the anchor to choose not to js . If you don't need an anchor, then use js . Get the href judgment and the href of the a tag in the new page. Add active this class

.

http://jsrun.net/UChKp/edit

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e455fb-44b24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e455fb-44b24.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?