定义 动态的导航栏高亮

来源:互联网 发布:mac 拷贝照片到u盘 编辑:程序博客网 时间:2024/05/22 02:14
    //获取页面的链接    var nowUrl = window.location.href;    nowUrl = nowUrl.split('/');//分离成数组 取最后边的一个 然后给他的父级添加class    //alert( nowUrl[nowUrl.length - 1])console.log(nowUrl)    $('.order_type a[href*="' + nowUrl[nowUrl.length - 1] + '"]').addClass('order_text');    var urlstr = window.location.href;    //获取浏览器的url    var urlstatus=false;        //标记    //遍历导航div    $(".order_status td a").each(function() {//判断导航里面的relurl地址是否相等        url=$(this).attr('href');        console.log(url[0])        if((url).indexOf(nowUrl[nowUrl.length - 1]) > -1&&$(this).attr('rel')!='')        {            $(this).addClass('order_text');            urlstatus = true;        }        else{            $(this).removeClass('order_text');        }    });    //当前样式保持    if(!urlstatus)    {$(".order_status a ").eq(0).addClass('order_text');    }
0 0