如果菜单项url==当前url,我有以下代码可以将活动css类添加到菜单项:
$("#accordion a").each(function()
{
if (this.href.search(window.location.hostname) != -1)
{
$(this).addClass("active-sidebar-link");
}
});
但这会将该类添加到所有菜单项中。有什么提示吗?
试试看:
$("#accordion a").each(function() {
if (this.href == window.location.href) {
$(this).addClass("active-sidebar-link");
}
});