导航点击字体变色

1、CSS

 .active {
            color: #ff5837;
        }

2、js

$(".header ul li a").each(function(){
$this = $(this);
if($this[0].href==String(window.location)){ 
$(".header ul li a").removeClass("active");
$this.addClass("active"); 
} 
});

3、方法2

 

var urlstr = location.href;
			var urlstatus = false;
			$("#navigate a").each(function() {
				if ((urlstr + '/').indexOf($(this).attr('href')) > -1 && $(this).attr('href') != '') {
					$(this).addClass('active');
					urlstatus = true;
				} else {
					$(this).removeClass('active');
				}
			});
			if (!urlstatus) {
				$("#navigate a").eq(0).addClass('active');
			}

  

 

posted @ 2017-08-02 13:48  漫天风沙  阅读(543)  评论(0编辑  收藏  举报