4

我是引导程序的新手,我对此有疑问

如果我有这样的下拉菜单导航栏代码

<div class="navbar-collapse collapse">
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Menu <b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><a href="#menu1">menu 1</a></li>
            <li><a href="#menu2">menu 2</a></li>
            <li><a href="#menu3">menu 3</a></li>
        </ul>
</div>

如果我单击其中一个菜单,则链接将包括这样的“www。...../#menu1”

问题是如果我想让内容出现在我只需点击的菜单上,我该怎么做?

<div class="container">
    <!-- my rough idea is like this-->
    <div id="#menu1"> content from menu 1</div>
    <div id="#menu2"> Content from menu 2</div>
    <div id="#menu3"> Content from menu 2</div>
</div>

我已经尝试了很多次,但它仍然显示两个数据。我已经像这样从JavaScript(来自引导程序)中包含了

<script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
<script src="../bootstrap/js/bootstrap.min.js"></script>
4

1 回答 1

4

You need to use jQuery to show hide the content. Try this:

  1. Add a class="content" to your divs and remove the # from ID

    <div id="menu1" class="content"> content from menu 1</div>

  2. Add a jQuery event to you nav links

    $(".dropdown-menu a").on('click',function(e) {
       e.preventDefault(); // stops link from loading
       $('.content').hide(); // hides all content divs
       $('#' + $(this).attr('href') ).show(); //get the href and use it find which div to show
    });
    

Hope that helps //Edit

于 2013-10-25T00:38:54.623 回答