html 将类激活添加到当前页面菜单链接https://htmlcssphptutorial.wordpress.com/2015/06/30/jquery-automatically-highlig

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html 将类激活添加到当前页面菜单链接https://htmlcssphptutorial.wordpress.com/2015/06/30/jquery-automatically-highlig相关的知识,希望对你有一定的参考价值。


<a class="{{$pages->url}}" href="{{ URL::to('/pages/'.$pages->url) }}">{{ $pages->title }}</a>

<script>

$(function () {

  var curPageSlug = (window.location.pathname.match(/[^\/]+$/)[0]);
  
  // si le queremos agregar la clase 'active' solo al link
  $('.'+curPageSlug).addClass('active');
  
  // si le queremos agregar la clase 'active' al link y al parent
  $('.'+curPageSlug).each(function(){
    $(this).addClass('active');
    $(this).closest('.dropdown').addClass('active');
  });

});

</script>

以上是关于html 将类激活添加到当前页面菜单链接https://htmlcssphptutorial.wordpress.com/2015/06/30/jquery-automatically-highlig的主要内容,如果未能解决你的问题,请参考以下文章