效果:

JS:
$(function () {
  //遍历list(一般为ul li)
  $("#menu a").each(function () {
    //给当前项添加点击事件(点击后切换样式)
    $(this).bind('click',function () {
       // 移除其他所有项的active类
       $("#menu a").each(function () {
           $(this).removeClass('active');
       })
       // 给当前项添加active类
       $(this).addClass('active');
    })
  });
})















![[练习]如何使用递归算法?](https://i-blog.csdnimg.cn/direct/def5ae877ca24e509b574aff520f0778.jpeg)

