很多开发小伙伴不知道怎么让当前导航高亮选中, 很多人都陷入误区,用php写各种判断, 开发效率极慢 博主写法仅供参考
注意:要jquery支持
html部分
<ul class="nav-active-test"> <li><a href="/xxx">test</a></li> </ul>
css部分
.nav-active-test .active a{ color: red; }
script部分
$(".nav-active-test a").each(function() { if ($(this)[0].href == String(window.location)) { $(this).parents("li").addClass("active"); return false; }})
No Data