1. 二宝博客首页
  2. JS相关

js jq 当前栏目高亮

    
    
    
  •  网站首页
  •  总会荣誉
  •  慈善新闻
  •  慈善项目
  •  善款公开
  •  政策法规
  •  政策解读
  •  慈善文化
  •  慈善报
  •  慈善志愿者
  •           
      var urlstr = location.href;  
      //alert(urlstr);  
      var urlstatus=false;  
      $("#topnav a").each(function () {  
        if ((urlstr + '/#').indexOf($(this).attr('rel')) > -1&&$(this).attr('rel')!='') {  
          $(this).addClass('am-active'); urlstatus = true;  
        } else {  
          $(this).removeClass('am-active'); 
        }  
      });
     // alert(urlstatus);
      if (!urlstatus) {$("#topnav a").eq(0).addClass('am-active'); }

    需要说明 首页链接必须为”/#” 不然可能会冲突 导致其他栏目首页高亮不消失

    ]]>

    原创文章,作者:键盘游走者,如若转载,请注明出处:https://www.708034.com/2017/12/js-jq-%e5%bd%93%e5%89%8d%e6%a0%8f%e7%9b%ae%e9%ab%98%e4%ba%ae/

    发表评论

    电子邮件地址不会被公开。 必填项已用*标注