在点击nav后,用JS加上颜色,怎么在页面跳转后仍能保持改变后的颜色?

https://img2.mukewang.com/5c120a860001df8b07190042.jpg

导航每个页面都是通过后台标签链接的同一个段HTML,我在点击导航后,通过js加上改变颜色,但是点击跳转到能一个页面,js改后的颜色就失效了,请问这种问题怎么解决?

不负相思意
浏览 732回答 1
1回答

回首忆惘然

我自己来回答吧,不用你们写的那么复杂,每个页面加入一段CSS方法一://首页ul li a:nth-child(1){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #FF0000;&nbsp; &nbsp; &nbsp; &nbsp; }//品牌介绍ul li a:nth-child(2){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; color: #FF0000;&nbsp; &nbsp; &nbsp; &nbsp; }//招牌美食ul li a:nth-child(3){&nbsp; &nbsp; .........}方法二:&nbsp;$(function() {&nbsp; &nbsp; var pageUrl = window.location.href;&nbsp; &nbsp; var aArray = $("ul>li>a");&nbsp; &nbsp; for (var i = 1; i < aArray.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; //高亮首页栏目&nbsp; &nbsp; &nbsp; &nbsp; if (pageUrl == aArray[0].href) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(aArray[0]).addClass("active");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; //高亮当前栏目,如果为子栏目时,则匹配 href 亮父栏目&nbsp; &nbsp; &nbsp; &nbsp; else if (pageUrl.substring(0, aArray[i].href.length) == aArray[i].href) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $(aArray[i]).addClass("active");&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }})
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript