Displaying active navigation based on contextual data

后端 未结 6 1176
礼貌的吻别
礼貌的吻别 2021-02-07 00:36

I have the following separated fragment in a Thymeleaf template.

6条回答
  •  北海茫月
    2021-02-07 00:56

    May be this code would be helpful for someone. Attention! It's not Thymeleaf solution, just js code which you can add on your pages.

    var currentPage = location.href.match(/(.*?)([^\/]+)$/).pop();
            $(Array.prototype.filter.call($('.menu-head li a:nth-child(1)'), function(item)
            {
                return item.href.endsWith(currentPage)
            })).parents('li').addClass('active');
    

提交回复
热议问题