单击链接时折叠Booststrap

时间:2015-09-21 15:48:45

标签: javascript html css twitter-bootstrap navigation

我使用展开和折叠而不是使用下拉列表构建了一个导航菜单。我的问题是,当我点击菜单链接时,我无法切换div。我已尝试使用js在点击链接时关闭它,但我无法再次重新打开菜单。

这是我的HTML:

<header style="padding:0px 0%;">
 <nav class="navbar navbar-inverse navbar-static-top" style="margin:0px 0px;">
  <div class="container">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header hidden-md hidden-lg">
      <button type="button" class="navbar-toggle collapsed hidden-sm hidden-xs" data-toggle="collapse" data-target="#myNavmenu" aria-expanded="true" style="color:#fff;display:inline-block;">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse">
      <ul class="nav navbar-nav navbar-right inverse hidden-xs hidden-sm" style="margin:0px 0px; font-size:0.8em;">
          <li style="float:left !important"><a href="/" style="text-align: left; padding:8px 0px;"><img src="/products/greg2/images/avatierwatermark.png" style="height:34px; width:auto;"></a></li>
          <li><a href="#">Customers</a></li>
         <li><a href="#">Solutions</a></li>
           <li><a href="#">Products</a></li>
      </ul>

    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>
</header>


<div class="collapse" id="expandmenu">
  <div class="well">
        <div class="container">
             <button type="button" class="navbar-toggle2 pull-right" data-toggle="collapse" href="#expandmenu" aria-expanded="false" aria-controls="collapseExample" style="float:right; padding:16px 5px 17px 0px; color:#333;"><p class="explore" style="font-size:0.8em; color:#333;">Close </p>
  <span class="glyphicon glyphicon-remove" aria-hidden="true" style="font-size:1.1em;"></span>
</button>
             <div class="row">
                 <div class="col-sm-12">

            </div>
                 </div>

    <div class="row">


        <ul class="expand txt-ctr" style="padding-left:0px;">
            <li class="blue"><a href="#passwordstationbenefits" data-toggle="collapse" aria-expanded="false" aria-controls="collapseExample"><div style="background-position:0px 0px;"></div><span>Benefits</span></a></li>
            <li class="blue"><a href="#overview" data-toggle="collapse" aria-expanded="false" aria-controls="collapseExample"><div style="background-position:-165px 0px;"></div><span>Overview</span></a></li>
            <li class="blue"><a href="#design"><div style="background-position:-330px 0px;"></div><span>Features</span></a></li>
            <li class="blue"><a href="#reporting"><div style="background-position:-495px 0px;"></div><span>Reports</span></a></li>
            <li class="blue"><a href="#security"><div style="background-position:-660px 0px;"></div><span>Security</span></a></li>
            <li class="blue"><a href="#helpdesk"><div style="background-position:-825px 0px;"></div><span>Help Desk</span></a></li>
            <li class="blue"><a href="#appsupport"><div style="background-position:-990px 0px;"></div><span>App Support</span></a></li>
            <li class="blue"><a href="#architecture"><div style="background-position:-1155px 0px;"></div><span>Architecture</span></a></li>
            <li class="blue"><a href="#languages"><div style="background-position:-1315px 0px;"></div><span>Languages</span></a></li>
            <li class="blue"><a href="#ticketing"><div style="background-position:-1490px 0px;"></div><span>Ticketing</span></a></li>
            <li class="blue"><a href="#textimonials"><div style="background-position:-1665px 0px;"></div><span>Testimonials</span></a></li>
            <li class="blue"><a href="/products/identity-management/password-management/password-station/demo/"><div style="background-position:-1825px 0px;"></div><span>Demo</span></a></li>
             <li class="blue"><a href="#resources"><div style="background-position:-1998px 0px;"></div><span>Resources</span></a></li>
            <li class="blue"><a href="#payingtwice"><div style="background-position:-2165px 0px;"></div><span>True Cost</span></a></li>
                </ul>

</div>
 </div>
  </div>
</div>

这是我尝试过的人:

$('.collapse a').click(function(){
  $("#expandmenu").toggle();
});

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

试试这个,它对我有用:

$('#expandmenu a').click(function(){
  $("#expandmenu button").click();
});