简体   繁体   English

单击链接后,导航栏中的子菜单崩溃

[英]Submenu in navbar is collapsing after click on link

I have a navbar on the left side of my web application with each item of the menu having an expandable submenu to navigate through the pages. 我在Web应用程序的左侧有一个导航栏,菜单的每个项目都有一个可扩展的子菜单来浏览页面。 Unfortunately, every time I click on one of the links of a submenu the new page is loaded, but the submenu is collapsed again. 不幸的是,每次我单击子菜单的链接之一时,都会加载新页面,但是该子菜单会再次折叠。 I would like to have the submenu still expanded after clicking one of its links. 我希望子菜单在单击其链接之一后仍能展开。

Here is my code: 这是我的代码:

 <div class="container-fluid"> <div class="row"> <div class="col-md-3"> <div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true"> <div class="nav-header panel panel-default"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseOne" aria-expanded="false" aria-controls="collapseOne"> <div class="panel-heading" role="tab" id="headingOne"> <h4 class="panel-title"> <span class="glyphicon glyphicon-th"></span>Cluster </h4> </div> </a> <div id="collapseOne" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingOne"> <div class="panel-body"> <div class="nav-item"><span class="glyphicon glyphicon-eye-open"></span>@Html.ActionLink("overview", "ClusterAll", "Cluster", new { area = "" }, new { @class = "nav-item", style = "text-decoration:none;" })</div> <div class="nav-item"><span class="glyphicon glyphicon-plus"></span>@Html.ActionLink("create", "ClusterCreation", "Cluster", new { area = "" }, new { @class = "nav-item", style = "text-decoration:none;" })</div> <div class="nav-item"><span class="glyphicon glyphicon-pencil"></span>@Html.ActionLink("edit", "ClusterEdit", "Cluster", new { area = "" }, new { @class = "nav-item", style = "text-decoration:none;" })</div> </div> </div> </div> <div class="nav-header panel panel-default"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapseTwo" aria-expanded="false" aria-controls="collapseTwo"> <div class="panel-heading" role="tab" id="headingTwo"> <h4 class="panel-title"> <span class="glyphicon glyphicon-hdd"></span>Applications </h4> </div> </a> <div id="collapseTwo" class="panel-collapse collapse" role="tabpanel" aria-labelledby="headingTwo"> <div class="panel-body"> <div class="nav-item"><span class="glyphicon glyphicon-ok"></span>@Html.ActionLink("verify", "ApplicationPortfolioEdit", "Applications", new { area = "" }, new { @class = "nav-item", style = "text-decoration:none;" })</div> <div class="nav-item"><span class="glyphicon glyphicon-list-alt"></span>@Html.ActionLink("manage", "ApplicationMassEdit", "Applications", new { area = "" }, new { @class = "nav-item", style = "text-decoration:none;" })</div> </div> </div> </div> </div> </div> </div> </div> 

The actual menu has more items, this is just an example with 2 items to show you. 实际菜单中有更多项目,这只是一个示例,其中有2个项目向您显示。 Any ideas what I have to do to keep the submenus expanded after clicking on its links? 单击该链接后,我有什么想法要使子菜单保持展开状态? I'm very new to web design, but I hope you can help me:) 我是网页设计的新手,但希望您能为我提供帮助:)

If I get what you're trying to do you can pass the opened submenu as a # param in your url so when they do click a link to the new page you can have Javascript/jQuery read the # and open the proper submenu. 如果我知道您要执行的操作,则可以在URL中将打开的子菜单作为#参数传递,因此当他们单击指向新页面的链接时,您可以让Javascript / jQuery阅读#并打开适当的子菜单。

Something like this.. 像这样

<a href="page.html#menuItemClicked">Applications</a>

And then with Javascript & jQuery we can read it with.. 然后,使用Javascript和jQuery,我们可以使用它进行阅读。

 $(document).ready(function() { hash = window.location.hash; $(hash).collapse('show'); }); 

We can use $(hash).collapse('show'); 我们可以使用$(hash).collapse('show'); to show the content because you're using Bootstrap. 显示内容,因为您使用的是Bootstrap。

But this goes under the impression I understand what you're trying to say. 但这给人的印象是我理解您要说的话。 :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM