引导 JavaScript 不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30192263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 04:46:57  来源:igfitidea点击:

Bootstrap JavaScript not working

javascripttwitter-bootstrap

提问by user289040

My toggle javascript buttons worked initially - however I have now found that my toggle button including navbar collapsing toggle and accordion panels. I have included my header and footer. From what I have researched I cant see why it has stopped working. Any help would be appreciated.

我的切换 javascript 按钮最初有效 - 但是我现在发现我的切换按钮包括导航栏折叠切换和手风琴面板。我已经包括了我的页眉和页脚。根据我的研究,我看不出它为什么停止工作。任何帮助,将不胜感激。

Header: WEBSITE TITLE

标题:网站标题

    <!-- Bootstrap -->
    <link href="style/css/bootstrap.min.css" rel="stylesheet">
    <!--load font awesome-->
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>

    <![endif]-->
  </head>

Footer:

页脚:

 <footer>
<div class="container">
        <p>&copy; Company 2015</p>
      </footer>
    </div> <!-- /container -->
</div>
  </body>

 <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="../../dist/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script>
  </body>
</html>

采纳答案by Coding Enthusiast

I guess you just copied what was said on the bootstrap side for example:

我想您只是复制了引导程序方面的内容,例如:

<script src="../../dist/js/bootstrap.min.js"></script>

If you have the js bootstrap file in one of your folders in the root, you might want to make sure it is the path is right. For example if your html file is in the same directory as your bootstrap.min.js it should be <script src="bootstrap.min.js"></script>.

如果根目录中的某个文件夹中有 js 引导程序文件,则可能需要确保它的路径正确。例如,如果您的 html 文件与 bootstrap.min.js 位于同一目录中,则它应该是 <script src="bootstrap.min.js"></script>.

The quick fix you just did which is simply changing it to
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

您刚刚所做的快速修复只是将其更改为
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

Might solve the problem now but it will render your local bootstrap file useless which you can make useful by using a bootstrap cdn fallback. Which is basically loading your local bootstap files if you fail to load remote bootstrap files. This is how to make a bootstrap cdn callback

现在可能会解决问题,但它会使您的本地引导程序文件无用,您可以通过使用bootstrap cdn fallback. 如果您无法加载远程引导程序文件,这基本上是加载您的本地引导程序文件。这是如何进行引导 CDN 回调

回答by Sheo Dayal Singh

If you are using bootstap 3.x then you need at least jquery 1.9.1 version library.First download the jquery library and bootstrap js and include in your application and then register both in your application page.First register the jquery library and then bootsrap js as mentioned below.

如果您使用的是 bootstap 3.x,那么您至少需要 jquery 1.9.1 版本的库。首先下载 jquery 库和 bootstrap js 并包含在您的应用程序中,然后在您的应用程序页面中注册。首先注册 jquery 库,然后 bootsrap js 如下所述。

   <scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>

<script src="../../dist/js/bootstrap.min.js"></script>

回答by goodnesskay

if you check the console of the page, it should show a notice that jquery is not seen by javascript. so, you can solve this by downloading the jquery source code from the jquery site and then you can add the following line of code before the end of your footer: <script>window.jQuery || document.write('<script src="assets/js/jquery.min.js"><\/script>')</script>

如果您检查页面的控制台,它应该显示一个通知,即 javascript 看不到 jquery。因此,您可以通过从 jquery 站点下载 jquery 源代码来解决此问题,然后您可以在页脚末尾添加以下代码行: <script>window.jQuery || document.write('<script src="assets/js/jquery.min.js"><\/script>')</script>

回答by user289040

I changed the javascript tag displayed in my footer example from:

我将页脚示例中显示的 javascript 标记更改为:

<script src="../../dist/js/bootstrap.min.js"></script>

to

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>

This has resolved the problem.

这已经解决了问题。