给当前页或者跳转后页面的导航栏添加选中样式

html:

 1 <!-- footer start -->
 2   <footer class="navbar">
 3     <div class="item active">
 4       <span class="iconfont icon-icon"></span>
 5       <p>首页</p>
 6     </div>
 7     <div class="item">
 8       <span class="iconfont icon-yansetianchong1"></span>
 9       <p></p>
10     </div>
11   </footer>
12   <!-- footer end -->

jquery:

1 // footer active
2       $(document).ready(function(){
3         $('footer > div').each(function(){
4           $(this).click(function(){
5             $('footer > div').removeClass('active');
6             $(this).addClass('active');
7           })
8         })
9       });

猜你喜欢

转载自www.cnblogs.com/zrcassiel/p/10328885.html