简体   繁体   English

Javascript / Navbar下拉列表不适用于Twitter Bootstrap

[英]Javascript/Navbar Dropdown Not Working With Twitter Bootstrap

I'm trying to use the latest version of twitter bootstrap to create a navigation menu with dropdown links. 我正在尝试使用最新版本的twitter bootstrap创建带有下拉链接的导航菜单。

However, the dropdown doesn't work, and the collapsed navbar doesn't go back up. 但是,下拉菜单不起作用,并且折叠的导航栏也不会返回。

I'm assuming something in the javascript doesn't work, but I've double checked my hotlinks and they're all up and working. 我假设javascript中的某些内容不起作用,但是我仔细检查了我的热链接,它们都正常工作了。

Here's what I have in my head: 这就是我的想法:

    <!-- Le Javascript -->

<!-- Google Libraries for Charts and jquery -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript for Bootstrap-->
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

<!-- sharethis javascript -->
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "be79498d-c866-4538-945f-677020fd645d", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

<!-- Pesonal javascript files -->
<script src="../js/interactions.js"></script>
<script src="../js/data-model.js"></script>
<script src="../js/charts.js"></script>

<!-- Le CSS -->

<!-- Latest compiled and minified CSS for bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootswatch/3.3.4/yeti/bootstrap.min.css" rel="stylesheet">

<!-- Personal Style Sheet -->
<link rel="stylesheet" href="../css/calculator.css">

I don't see any issues with this. 我看不到任何问题。

Here's the html for the nav. 这是导航的html。 It was copied and pasted from the bootstrap source docs. 它是从引导源文档复制并粘贴的。

<nav class="navbar navbar-inverse">
      <div class="container-fluid">
        <!-- Brand and toggle get grouped for better mobile display -->
        <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" href="http://www.healthkismet.com">Health Kismet</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="active"><a href="http://www.healthkismet.com/formula-analyzer/">Formula Analyzer <span class="sr-only">(current)</span></a></li>
                <li><a href="http://www.healthkismet.com/formula-analyzer/how-to-use/">How To Use</a></li>
                <li><a href="#">Suppliers</a></li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Help <span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="#">Contact/FAQ</a></li>
                    <li><a href="http://forums.healthkismet.com">Forums</a></li>
                  </ul>
                </li>
                <li><a href="http://blog.healthkismet.com/starting-supplement-business">Get Help With Your Formula</a></li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">Blog <span class="caret"></span></a>
                  <ul class="dropdown-menu" role="menu">
                    <li><a href="http://blog.healthkismet.com">Company Blog</a></li>
                    <li><a href="http://blog.healthkismet.com/topics/entrepreneurship">Entrepreneurship Articles</a></li>
                  </ul>
                </li>
              </ul>
            </div><!-- /.navbar-collapse -->
        </div><!-- /.container-fluid -->
    </nav>

Not sure if it's something wrong with the bootstrap or if there's possible interference from other javascript files. 不知道引导程序是否有问题,或者其他JavaScript文件是否可能造成干扰。

You can view the whole page here: www.healthkismet.com/formula-analyzer/ 您可以在此处查看整个页面: www.healthkismet.com/formula-analyzer/

You have many of the same JS scripts and new and old versions. 您有许多相同的JS脚本以及新旧版本。

Please put all of these JS scripts below at the end of your page. 请在页面末尾将所有这些JS脚本放在下面。

<!-- Le Javascript -->

<!-- Google Libraries for Charts and jquery -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>


<!-- Le Javascript -->

<!-- Google Libraries for Charts and jquery -->
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<!-- Latest compiled and minified JavaScript for Bootstrap-->
<script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js">   </script>

<!-- sharethis javascript -->
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "be79498d-c866-4538-945f-677020fd645d", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>

<!-- Pesonal javascript files -->
<script src="../js/interactions.js"></script>
<script src="../js/data-model.js"></script>
<script src="../js/charts.js"></script>

And only use one css CDN link. 并且仅使用一个CSS CDN链接。 Also when using Bootstrap and custom css, the placement of your CSS can take priority over another in the order they get read in your page. 同样,在使用Bootstrap和自定义CSS时,CSS的放置可以优先于它们在页面中的读取顺序。

It will now works if you just use the JS scripts above. 如果您仅使用上面的JS脚本,它将立即起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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