Multi-level bootstrap 3.3.4 中的下拉菜单

Multi-level Dropdown in bootstrap 3.3.4

所以我正在尝试完成标题所说的 multi-level 下拉菜单。我只得到一个级别,第二个级别没有出现。我不确定我错过了什么。这是我拥有的:

        <div class="collapse navbar-collapse" id="conference-dropdowns">
        <ul class="nav navbar-nav">
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">AFC<span class="caret"></span></a>
                <ul class="dropdown-menu multi-level" role="menu">
                    <li class="dropdown-submenu">
                        <li><a href="/conference/1/division/1">AFC South</a></li>
                        <ul class="dropdown-menu">
                            <li><a href="/conference/1/division/1/team/1">Colts</a></li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
        <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
                <input class="form-control" placeholder="Search" type="text">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Logout</a></li>
        </ul>
    </div>

我在 bootstrap 3.3.4 上,刚刚获得 AFC for Dropdown,在里面只有 AFC South 出现。没有子菜单。任何帮助都会很棒。谢谢。我也在用 bootswatch spacelab

希望这就是您要找的^^

<div class="container">
 <div class="dropdown">
  <button class="btn btn-default dropdown-toggle" type="button" data-toggle="dropdown">AFC
    <span class="caret"></span></button>
  <ul class="dropdown-menu">
   <li><a tabindex="-1" href="#">AFC South</a></li>
   <li class="dropdown-submenu">
    <a class="test" tabindex="-1" href="#">New dropdown <span class="caret"></span></a>
    <ul class="dropdown-menu">
     <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
     <li><a tabindex="-1" href="#">2nd level dropdown</a></li>
     <!--<li class="dropdown-submenu">
            <a class="test" href="#">Another dropdown <span class="caret"></span></a>
            <ul class="dropdown-menu">
              <li><a href="#">3rd level dropdown</a></li>
              <li><a href="#">3rd level dropdown</a></li>-->
    </ul>
   </li>
  </ul>
 </div>
</div>
$(document).ready(function() {
 $(".dropdown-submenu a.test").on("click", function(e) {
  $(this)
   .next("ul")
   .toggle();
  e.stopPropagation();
  e.preventDefault();
 });
});

JSFiddle

这是我在测试它时发现的工作,现在我只需要使用 JS 动态地写出来。

<nav class="navbar navbar-default">
<div class="container-fluid">
    <div class="navbar-header">
        <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand pull-left" href="#"><img id="logo" src="${pageContext.servletContext.contextPath}/static/images/aston.png"></a>
    </div>

    <div class="collapse navbar-collapse" id="conference-dropdowns">
        <ul class="nav navbar-nav">
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">AFC<span class="caret"></span></a>
                <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
                    <li class="dropdown-submenu">
                        <a tabindex="-1" href="#">AFC South</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Colts</a></li>
                            <li><a href="#">Jaguars</a></li>
                            <li><a href="#">Titans</a></li>
                            <li><a href="#">Texans</a></li>
                        </ul>
                    </li>
                    <li class="dropdown-submenu">
                        <a tabindex="-1" href="#">AFC North</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Steelers</a></li>
                            <li><a href="#">Ravens</a></li>
                            <li><a href="#">Browns</a></li>
                            <li><a href="#">Bengals</a></li>
                        </ul>
                    </li>
                </ul>
            </li>
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">NFC<span class="caret"></span></a>
                <ul class="dropdown-menu multi-level" role="menu" aria-labelledby="dropdownMenu">
                    <li class="dropdown-submenu">
                        <a tabindex="-1" href="#">NFC North</a>
                        <ul class="dropdown-menu">
                            <li><a href="#">Packers</a></li>
                            <li><a href="#">Vikings</a></li>
                            <li><a href="#">Lions</a></li>
                            <li><a href="#">Bears</a></li>
                        </ul>
                    </li>
                </ul>
            </li>
        </ul>
        <form class="navbar-form navbar-left" role="search">
            <div class="form-group">
                <input class="form-control" placeholder="Search" type="text">
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
        </form>
        <ul class="nav navbar-nav navbar-right">
            <li><a href="#">Logout</a></li>
        </ul>
    </div>
</div>

HTML

        <div class="collapse navbar-collapse" id="conference-dropdowns">

            <ul class="nav navbar-nav">

                <li class="dropdown">
                    <a class="dropdown-toggle" data-toggle="dropdown" href="#">AFC <span class="caret"></span></a>
                    <ul class="dropdown-menu">

<!--                    submenu-->
                        <li class="dropdown-submenu">
                            <a class="submenu" data-toggle="dropdown" href="#">AFC South <span class="caret"></span></a>
                            <ul class="dropdown-menu">

                                <li class="dropdown-submenu">
                                    <a class="submenu" data-toggle="dropdown" href="#">Colts <span class="caret"></span></a>
                                    <ul class="dropdown-menu">
                                        <li><a href="#">Red </a></li>
                                    </ul>
                                </li>

                            </ul>
                        </li>
<!--                    submenu || -->

                    </ul>
                </li>

            </ul>
        </div>

CSS

    .dropdown-submenu {
        position: relative;
    }

    .dropdown-submenu .dropdown-menu {
        top: 0;
        left: 100%;
        margin-top: -1px;
    }

Codepen:Bootstrap 3 下拉多级插入符向上