简体   繁体   中英

jQuery Dropdown menu not displaying menu

I'm trying to implement a Bootstrap dropdown menu with this code:

<div class="dropdown">
      <!-- Link or button to toggle dropdown -->
        <a href="#" role="button" class="dropdown-toggle" data-toggle="dropdown">Dropdown <b class="caret"></b></a>
      <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
        <li><a tabindex="-1" href="#">Action</a></li>
        <li><a tabindex="-1" href="#">Another action</a></li>
        <li><a tabindex="-1" href="#">Something else here</a></li>
        <li class="divider"></li>
        <li><a tabindex="-1" href="#">Separated link</a></li>
      </ul>
    </div>

Looking at the Bootstrap docs, this is about the bare minimum needed for a dropdown menu, there is no other explanation provided in the docs. I have referenced Bootstrap and jQuery. I do not understand how this is supposed to work - and it doesn't in this current sample . Well obviously it needs something to tell it to show the menu, but I haven't been able to find a straight answer on what reference and file does what for the Bootstrap dropdown menu.

Question: So does this thing use jQuery to work or what? I don't understand why or how it works even after I found a simple working demo here from this SO question stackoverflow.com/questions/14023115/dropdown-menu-not-showing-in-bootstrap. I got it to work in this JSfiddle after importing Bootstrap.css and Bootstrap.min.js and Jquery 2. So it needs both Bootstrap.min.js AND Jquery to work? Huh? I'm just completely lost here. Thanks.

EDIT: Okay, found out that bootstrap.js needs to be loaded after jquery to work. But I still do not understand how the menu works. Does Bootstrap.js need Jquery?

All js plugins in bootstrap uses jquery

Plugin dependencies

Some plugins and CSS components depend on other plugins. If you include plugins individually, make sure to check for these dependencies in the docs. Also note that all plugins depend on jQuery (this means jQuery must be included before the plugin files).

source: http://getbootstrap.com/javascript/

The following post should help you.

Why doesn't this bootstrap dropdown example work?

You are gonna need both jquery and bootstrap referenced in the correct order and with html 5 doctype.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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