jquery 导航菜单点击切换事件

xiao
xiao
 $(function(){
    //获得当前页面 url 信息
    var url = window.location.href;    
    //先移除点击的样式
    $('.li_class').removeClass('active');
    $("ul li a").each(function(){
        //获得每个a标签的 url 信息
        var this_url = $(this).attr('href');
        //判断当前页面 然后为其添加样式
        if(this_url == url){
            $(this).attr('active-link');
            $(this).parents('.li_class').addClass('active');
        }
        
    })    
 })
Copyright

原创 本文由 xiao 发布于 xiao

原文链接:https://blog.joniding.com/index.php/archives/17/

许可协议CC BY-NC-ND 4.0署名-非商业性使用-禁止演绎 4.0 国际

发表评论