bootstrap~ Multi-level navigation (cascade navigation) Implementation Effect "code" _javascript tips

Source: Internet
Author: User

In bootstrap official, navigation is two level, more than two is impossible to achieve, the uncle looked for some third party information, finally found a good plug-in, use and effect are not bad, and now share with you

Plugin Address: http://vsn4ik.github.io/bootstrap-submenu/

First look, in the Uncle Backstage system display effect

Here's how it's implemented

1 reference three JS Plug-ins and a CSS class library

Copy Code code as follows:

<script src= "~/content/bootstraps/js/bootstrap-submenu.js" ></script>
<script src= "~/content/bootstraps/js/highlight.min.js" ></script>
<script src= "~/content/bootstraps/js/docs.js" ></script>
<link href= "~/content/bootstraps/css/bootstrap-submenu.css" rel= "stylesheet"/>

2 inserts the corresponding HTML code block, this example does not use the recursive generation code, uses the static level three structure, this looks clearer, the real production environment proposed uses the recursive production menu
Copy Code code as follows:

<ul class= "Nav nav-pills" >

@foreach (var item in Model)
{
if (item. Sons!= null && item. Sons.count > 0)
{

<li class= "Dropdown" >
<a data-submenu= "" data-toggle= "dropdown" tabindex= "0" > @item. Menuname<span class= "Caret" ></span></a>
<ul class= "Dropdown-menu" >
@foreach (var sub in item.) Sons)
{
if (sub. Sons!= null && item. Sons.count > 0)
{

<li class= "Dropdown-submenu" >
<a tabindex= "0" > @sub. Menuname</a>
<ul class= "Dropdown-menu" >
@foreach (var inner in sub. Sons)
{
<li>
<a href= "@inner. Linkurl "> @inner. Menuname</a>
</li>
}

</ul>
</li>
<li class= "Divider" ></li>

}

Else
{
<li><a href= "@sub. Linkurl "> @sub. Menuname</a></li>
}
}
</ul>
</li>
}
Else
{
<li><a href= "@item. Linkurl "> @item. Menuname</a></li>
}
}
</ul>


The final effect is the first diagram, and it is worth noting that if you want to use a split line between each menu, you can add <li class= "divider" ></li> this line of code.

Thank you for your reading! Article source Zhang Jianling

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.