大家好,我有一个问题我正在使用模板,它有一个侧边栏菜单
问题就像你看到当我点击组件时它正在打开但是当我点击其中的网格时,它正在关闭我不希望它关闭它应该保持打开状态。当我以html启动它时它正在工作但在mvc中它不起作用。是关于“回发”吗?如果是的话我该如何解决呢。 非常感谢你。
确定这是代码
<div id="container" class="row-fluid">
<!-- BEGIN SIDEBAR -->
<div id="sidebar" class="nav-collapse collapse">
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
<div class="sidebar-toggler hidden-phone"></div>
<!-- BEGIN SIDEBAR TOGGLER BUTTON -->
<!-- BEGIN RESPONSIVE QUICK SEARCH FORM -->
<div class="navbar-inverse">
<form class="navbar-search visible-phone">
<input type="text" class="search-query" placeholder="Search" />
</form>
</div>
<!-- END RESPONSIVE QUICK SEARCH FORM -->
<!-- BEGIN SIDEBAR MENU -->
<ul class="sidebar-menu">
<li class="has-sub active">
<a href="javascript:;" class="">
<span class="icon-box"> <i class="icon-dashboard"></i></span> Dashboard
<span class="arrow"></span>
</a>
<ul class="sub">
<li class="active"><a class="" href="@Url.Action("About","Home")">Dashboard 1</a></li>
<li><a class="" href="@Url.Action("Contact","Home")">Dashboard 2</a></li>
</ul>
</li>
<li class="has-sub">
<a href="javascript:;" class="">
<span class="icon-box"> <i class="icon-book"></i></span> UI Elements
<span class="arrow"></span>
</a>
<ul class="sub">
<li><a class="" href="@Url.Action("About","Home")">General</a></li>
<li><a class="" href="@Url.Action("About","Home")">Buttons</a></li>
<li><a class="" href="@Url.Action("About","Home")">jQuery UI Component</a></li>
<li><a class="" href="@Url.Action("About","Home")">Tabs & Accordions</a></li>
<li><a class="" href="@Url.Action("About","Home")">Typography</a></li>
<li><a class="" href="@Url.Action("About","Home")">Tree View</a></li>
<li><a class="" href="@Url.Action("About","Home")">Nestable List</a></li>
</ul>
这就像我需要为此编写jquery或js但我怎么能达到每个li类?
答案 0 :(得分:1)
var activeurl = window.location.pathname;
$('a[href="' + activeurl + '"]').parent('li').addClass('active');
$('a[href="' + activeurl + '"]').parent('li').parent('ul').parent('li').addClass('active');
这些代码解决了我的问题。