给a链接跳转后的页面添加class

 $(document).ready(function(){
              var test = window.location.href;//获取到当前页面的href
                     // console.log(test);
        //循环遍历点击的元素 a 
                 $('.page_nav ul li a').each(function(){
                     var url=$(this).attr('href');
                     //console.log(url);
//在循环遍历中比对,如果找到了与当前页面相同的href就给当前添加class
                     if(test==url){
                         $(this).addClass('active');
                     }
                 })

         })    

关注微信小程序  

这些年,我们经历了多轮的淘汰赛,每轮淘汰赛都面临不同的对手,但每轮淘汰赛中我们都发展了.
原文地址:https://www.cnblogs.com/future-zmq/p/7667882.html