我有以下代码,如果菜单项url == current 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"); } });