请教用JS实现导航栏高亮,鼠标经过时和当前

2025-02-26 19:04:52
推荐回答(1个)
回答1:



 

  
  • 首页

  •   
  • 栏目一

  •   
  • 栏目二


  •  

      var urlstr = location.href;
      //alert(urlstr);
      var urlstatus=false;
      $("#menu a").each(function () {
        if ((urlstr + '/').indexOf($(this).attr('href')) > -1&&$(this).attr('href')!='') {
          $(this).addClass('cur'); urlstatus = true;
        } else {
          $(this).removeClass('cur');
        }
      });
      if (!urlstatus) {$("#menu a").eq(0).addClass('cur'); }