引导崩溃组件不关闭点击菜单 [英] Bootstrap collapse component not closing menu on clicking away

查看:136
本文介绍了引导崩溃组件不关闭点击菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击离开菜单不隐藏,我发现这个代码:
http://getbootstrap.com / components /#navbar
,但不能正常工作。

When I click away the menu doesn't hide, I found this code at: http://getbootstrap.com/components/#navbar but doesn't work as it should.

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container-fluid">
    <!-- Brand and toggle get grouped for better mobile display -->
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" 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" href="index.php">
        <img class="desktop-logo" src="img/logo.png" alt="Company title">
        <img class="mobile-logo" src="img/logo-white.png" width="169" alt="">
      </a>
    </div>

    <!-- Collect the nav links, forms, and other content for toggling -->
    <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
      <ul class="nav navbar-nav">
        <li class=""><a href="index.php">List</a></li>
      </ul>
    </div><!-- /.navbar-collapse -->
  </div><!-- /.container-fluid -->
</nav>

是的,我得到:安装了正确的库:Bootstrap v3.0.3。
没有javascript错误,并且HTML代码有效。

Yes, I got: proper libraries installed: Bootstrap v3.0.3. There are no javascript errors, and the HTML code is valid.

重现步骤:
下载bootstrap 3.0.3 zip包,一个index.html文件,插入css和js的东西为bootstrap。
输入上面的代码,点击或触摸时不会关闭。

Steps to reproduce: Download the bootstrap 3.0.3 zip package, make an index.html file, insert the css and js stuff for bootstrap. Enter the above code, and it's not closing when click or touched away.

那么,代码是否隐藏菜单?

So is the code meant to hide the menu or not ?

推荐答案

这应该

<script>
$(document).on('click',function(){
$('.collapse').collapse('hide');
})
</script> 

这是参考要点

a href =https://gist.github.com/winnyboy5/8750551> https://gist.github.com/winnyboy5/8750551

https://gist.github.com/winnyboy5/8750551

这篇关于引导崩溃组件不关闭点击菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆