JS根据url判断当前标签是否激活

来源:互联网 发布:阿里云域名接入 编辑:程序博客网 时间:2024/06/16 04:23

例子:

$(function(){

    $(".treeview-menu li a").each(function(){
        var local_href = 'http://www.baidu.com'+$(this).attr('href');
      if(local_href == String(window.location)){     
          $(this).css('color','#ffaa25');
           $(this).parent().parent().parent().addClass("active");
       }
    });

})


例子:

//页面激活   被选中li添加class=active
    $(function(){
         $(".daohang li").each(function(){
            if($(this).children('a')[0].href==String(window.location)){         
                $(this).addClass("active");
            }
        })
    }) 

0 0