如何将活动类添加到codeigniter超链接?

我知道这个问题很多,但我无法弄清楚如何使用已经回复的post来做到这一点。

我有一个带导航链接的标题。 我想将class="active"添加到此时class="active"的链接。

如果我有以下导航,我怎么能这样做?

  

我试过这个,但它不起作用:

  $(function() { var href = $(this).find('a').attr('href'); alert(window.location.pathname) if (href === window.location.pathname) { $(this).addClass('active'); } });  

也许有更好的Codeigniter-ish方式?

尝试这个。我认为不需要javascript或jquery。

如果您使用的是codeigniter,那么您可以使用URI类。

 
  • " href=""> BEDRIJF ZOEKEN
  • 如果您遇到任何问题,请告诉我

    我创建了一个帮助器并保存到名为“menu_helper.php”的帮助程序目录中:

     router->fetch_class(); return ($class == $controller) ? 'active' : ''; } } 

    然后在config / autoload.php中,我在第91行添加“menu”作为助手。

    最后一步是在访问页面时将代码打印为“活动”类(即登录页面):

     
  •  if (href === window.location.pathname) { $('a[href='+ href +']').addClass('active'); } 

    试试这个: