简体   繁体   English

Bootstrap崩溃导航栏可在jsfiddle上使用,在实际网站上不可用

[英]Bootstrap collapse navbar works on jsfiddle, doesn't work on actual website

I usually find answers to my simple questions without asking but not this time. 我通常不问就找到简单问题的答案,但是这次却没有。 It's been several days so I thought I'd ask. 已经好几天了,所以我想问一下。

The html code I have below: 我在下面的HTML代码:

  • You'll see I tried to do a few things to make see what was wrong 您会看到我尝试做一些事情来弄清楚出了什么问题
  • I tested to make sure the js libraries were loading (both Google and jquery) 我测试以确保js库正在加载(Google和jquery)
  • I tried redownloading bootstrap.min.js from bootstrap website (no change) 我尝试从bootstrap网站重新下载bootstrap.min.js(没有变化)
  • I tried getting bootstrap.min.js via CDN 我试图通过CDN获取bootstrap.min.js
  • I'm sure the answer is simple, but I can't quite figure it out (jsfiddle link at bottom) 我敢肯定答案很简单,但是我不太清楚(底部的jsfiddle链接)

Any help would be much appreciated. 任何帮助将非常感激。

    <!DOCTYPE html>
    <html>
    <head>
        <!-- Import all the necessary stylesheets-->
        <meta name="viewport" content ="width=device-width, inital-scale=1.0">
        <meta charset="utf-8">
        <title>This is the title</title>
        <link rel="stylesheet" href="css/bootstrap.css" type="text/css">
        <link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
        <link href="css/styles.css" media="screen" rel="stylesheet" type="text/css" />
        <link rel="stylesheet" href="fonts/font-awesome/css/font-awesome.min.css">
        <!--<link href="//cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">-->
        <!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> -->

        <style type="text/css">
            html, body {
                font-family: "Lato";
                height: 100%;
                margin-bottom: 100px;
            }
        </style>

    </head>

    <body>
        <!--Navigation bar-->
        <div class="row-fluid">
            <div class = "navbar navbar-inverse navbar-fixed-top">
                <div class = "container">
                    <a href = "#" class = "navbar-brand">brand</a>

                    <!--Collapse menu with three lines-->
                    <button type = "button" class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
                        <span class = "icon-bar"></span>
                        <span class = "icon-bar"></span>
                        <span class = "icon-bar"></span>
                    </button>

                    <!--Actual menu-->
                    <div class ="collapse navbar-collapse navHeaderCollapse">
                        <ul class = "nav navbar-nav navbar-right">
                            <li class = "active"><a href = "#">Home</a></li>
                            <li><a href = "#">Blog</a></li>
                            <li><a href = "#">About</a></li>
                            <li><a href = "#contact">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div>




        <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>-->
        <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
        <!--<script src=”js/bootstrap.js”></script>-->
        <script src=”js/bootstrap.min.js”></script>
        <script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
        <!--use code below to check if javasciprt library loaded-->
        <!--<script type="text/javascript">
        if (typeof jQuery != 'undefined') {
        alert("jQuery library is loaded!");
        }else{
        alert("jQuery library is not found!");
        }
        </script>-->
    </body>
</html>

Here's the jsfiddle where it's working - http://jsfiddle.net/moseslo/D2Gsa/1/ 这是jsfiddle工作的地方-http: //jsfiddle.net/moseslo/D2Gsa/1/

Fix wrong aposthrophes in line: 修正错误的撇号:

<script src=”js/bootstrap.min.js”></script>

And why are you loading bootstap.min.js twice? 为什么还要两次加载bootstap.min.js?

Try to use only one Bootstrap JS version here, so you can remove: 在此处尝试仅使用一个Bootstrap JS版本,因此可以删除:

<script src=”js/bootstrap.min.js”></script>

and only keep: 并且仅保留:

<script type="text/javascript" src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>

There are two possibilities, which should show erros on console: 有两种可能性,应该在控制台上显示错误:

  1. You have wrong ” in <script src=”js/bootstrap.min.js”></script> 您在<script src=”js/bootstrap.min.js”></script>有错误的“”
  2. You don't host you page and You use file:// scheme for viewing your page. 您没有托管页面,而是使用file://方案查看页面。

Anyway the fixed code below: 无论如何,下面的固定代码:

<!DOCTYPE html>
<html>
<head>
    <!-- Import all the necessary stylesheets-->
    <meta name="viewport" content ="width=device-width, inital-scale=1.0">
    <meta charset="utf-8">
    <title>This is the title</title>
    <link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" type="text/css">
    <link href='http://fonts.googleapis.com/css?family=Lato:400,700' rel='stylesheet' type='text/css'>
    <link href="css/styles.css" media="screen" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" href="http://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.0.3/css/font-awesome.min.css">
    <!--<link href="//cdn-images.mailchimp.com/embedcode/slim-081711.css" rel="stylesheet" type="text/css">-->
    <!-- <link href="//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css" rel="stylesheet"> -->

    <style type="text/css">
        html, body {
            font-family: "Lato";
            height: 100%;
            margin-bottom: 100px;
        }
    </style>

</head>

<body>
    <!--Navigation bar-->
    <div class="row-fluid">
        <div class = "navbar navbar-inverse navbar-fixed-top">
            <div class = "container">
                <a href = "#" class = "navbar-brand">brand</a>

                <!--Collapse menu with three lines-->
                <button type = "button" class = "navbar-toggle" data-toggle = "collapse" data-target = ".navHeaderCollapse">
                    <span class = "icon-bar"></span>
                    <span class = "icon-bar"></span>
                    <span class = "icon-bar"></span>
                </button>

                <!--Actual menu-->
                <div class ="collapse navbar-collapse navHeaderCollapse">
                    <ul class = "nav navbar-nav navbar-right">
                        <li class = "active"><a href = "#">Home</a></li>
                        <li><a href = "#">Blog</a></li>
                        <li><a href = "#">About</a></li>
                        <li><a href = "#contact">Contact</a></li>
                    </ul>
                </div>
            </div>
        </div>
    </div>




    <!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>-->
    <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
    <!--<script src=”js/bootstrap.js”></script>-->
    <script type="text/javascript" src="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
    <!--use code below to check if javasciprt library loaded-->
    <!--<script type="text/javascript">
    if (typeof jQuery != 'undefined') {
    alert("jQuery library is loaded!");
    }else{
    alert("jQuery library is not found!");
    }
    </script>-->
</body>

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

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