Php循环获取Nav导航后无法添加选中样式问题
问题描述 : 项目中后台嵌套后发现,Nav导航点击跳转无法添加当前选中样式,解决方案如下
大概思路 : 循环遍历判断跳转A标签中的Href,有的话跟浏览器比对,一致则加ClassName
//引入JQurey文件
<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">
$(".slide-left-bar ul li a").each(function(){
if ($(this)[0].href == String(window.location) && $(this).attr('href')!="") {
$(this).parents("li").addClass("right-on");
}
});
</script>
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。