我试图使用Bootstrap使一个程序的接口。我添加了jQuery 1.11.0到<head>标签,并认为这是,但当我在浏览器中启动网页jQuery报告一个错误:

Uncaught Error: Bootstrap's JavaScript requires jQuery

我已经尝试使用jQuery 1.9.0,我已经尝试在几个cdn上托管副本,但我不能让它工作。有人能指出我做错了什么吗?


当前回答

在解决了这个问题之后,我采取了三个步骤:

使用jQuery 1.9.0到3.0.0之间的任何版本 在声明Bootstrap文件之前声明jQuery文件 将这两个脚本文件声明在<body></body>标签的底部,而不是在<head></head>。 这些方法对我来说很有效,但是基于你所使用的浏览器可能会有不同的行为。

其他回答

试试这个

改变JS文件的顺序。它应该如下所示。

<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/wow.min.js"></script>

我正在使用NodeJS,得到了同样的错误。和其他答案一样,这个问题也是因为在Bootstrap之前需要加载JQuery;然而,由于NodeJS的特性,这个更改必须应用在pipeline.js文件中。

在pipeline.js中的变化是这样的:

var jsFilesToInject = [
  // Dependencies like jQuery, or Angular are brought in here
  'js/dependencies/angular.1.3.js',
  'js/dependencies/jquery.js',
  'js/dependencies/bootstrap.js',
  'js/dependencies/**/*.js',
];

我还使用grunt来帮助,它自动改变了主html页面的顺序:

<!--SCRIPTS-->
  <script src="/js/dependencies/angular.1.3.js"></script>
  <script src="/js/dependencies/jquery.js"></script>
  <script src="/js/dependencies/bootstrap.js"></script>
  <!-- other dependencies -->
<!--SCRIPTS END-->

希望能有所帮助!你没有说你的环境是什么,所以我决定发布这个答案。

官方文件: https://electronjs.org/docs/faq#i-can-not-use-jqueryrequirejsmeteorangularjs-in-electron

<head>
  <script>
  window.nodeRequire = require;
  delete window.require;
  delete window.exports;
  delete window.module;
  </script>
  <script type="text/javascript" src="jquery.js"></script>
</head>

以上的方法我几乎都试过了。

最后通过包含

script src="{%static 'App/js/jquery.js' %}"

在base.html中加载staticfiles后,即{% load staticfiles %}

如果你使用require.js,那么需要添加 窗口。$ = window。jQuery = require(' jQuery ')在app.js中

或 你可以让从属文件加载后,父文件加载..如下面的概念

require.config({
    baseUrl: "scripts/appScript",
    paths: {
        'jquery':'jQuery/jquery.min',
        'bootstrap':'bootstrap/bootstrap.min' 
    },
   shim
    shim: {
        'bootstrap':['jquery'],
        },

    // kick start application
    deps: ['app']
});

上面的代码表明bootstrap依赖于Jquery,所以我添加了shim并使其依赖