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

Uncaught Error: Bootstrap's JavaScript requires jQuery

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


当前回答

官方文件: 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>

其他回答

在添加bootstrap-之前,需要先添加JQuery

<!-- JQuery Core JavaScript -->
<script src="lib/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="lib/js/bootstrap.min.js"></script>

在添加bootstrap js文件之前,需要先添加JQuery js,因为bootstrap使用jqueries函数。所以请确保首先加载jquery js,然后引导js文件。

<!-- JQuery Core JavaScript -->
<script src="app/js/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="app/js/bootstrap.min.js"></script>

如果这种情况只发生在IE内网,请检查兼容性设置并取消选中“以兼容性模式显示内网站点”。

IE - >设置- >兼容性

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

最后通过包含

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

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

我正在使用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-->

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