在js中添加如下代码:
$(function () { $("#nav-bar").find("li").each(function () { var a = $(this).find("a:first")[0]; if ($(a).attr("href") === location.pathname) { $(this).addClass("active"); } else { $(this).removeClass("active"); } }); })
在js中添加如下代码:
$(function () { $("#nav-bar").find("li").each(function () { var a = $(this).find("a:first")[0]; if ($(a).attr("href") === location.pathname) { $(this).addClass("active"); } else { $(this).removeClass("active"); } }); })