js获取给与当前页面相同的a标签加类名

jianfly.com 2019-01-31 1546次浏览

实例

<script type="text/javascript">
        $().ready(function() {
          var types = $(".nav li a");
          var currentType = window.location.href;
          for(i=0; i<types.length; i++){
            if(types[i] == currentType){
              $(types[i]).addClass("navon");
              }
              continue;
              i++;
            }
        });
      </script>