bootstrap 侧边栏被选中后展开并
<script>
$('.nav-pills').find('a').each(function () {
if (this.href == document.location.href || document.location.href.search(this.href) >= 0) {
$(this).addClass('active');
console.log($(this).parents());
console.log(typeof ($(this).parents()));
if ($(this).parents().hasClass('nav-treeview')) {
{#alert('true');#}
$(this).parents('.has-treeview').addClass('menu-open'); // 不熟悉js,用了比较笨的方法
$(this).parents('.nav-treeview').prevAll('a').addClass('active');
}
}
});
</script>
效果如图:


本文介绍了一种使用Bootstrap实现侧边栏菜单项在被选中后展开的方法。通过JavaScript遍历.nav-pills类下的所有链接,检查其href属性是否与当前页面URL匹配,若匹配则为该元素添加'active'类,并进一步展开其父级.nav-treeview类的菜单。
5743

被折叠的 条评论
为什么被折叠?



