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

Uncaught Error: Bootstrap's JavaScript requires jQuery

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


当前回答

如果代码看起来不错,请验证jQuery是否成功加载到服务器。在我的例子中,jQuery文件是由我的IDE发布到服务器的,但是web服务器只有一个0 KB的文件存根。由于没有内容,服务器无法将文件提供给浏览器。

在重新发布文件并验证服务器实际上接收了整个文件后,我的网页不再向我提供错误。

其他回答

你应该首先加载jQuery,因为Bootstrap使用jQuery特性。是这样的:

<!doctype html>
<html>
    <head>
        <link type="text/css" rel="stylesheet" src="css/animate.css">
        <link type="text/css" rel="stylesheet" src="css/bootstrap-theme.min.css">
        <link type="text/css" rel="stylesheet" src="css/bootstrap.min.css">
        <link type="text/css" rel="stylesheet" href="css/custom.css">
        
<!--   Shuffle your scripts HERE  -->
        <script src="js/jquery-1.11.0.min.js"></script>
        <script src="js/bootstrap.min.js"></script>
        <script src="js/wow.min.js"></script>
<!--   End  -->   

        <title>pyMeLy Interface</title>
    </head>
    <body>
        <p class="title1"><strong>pyMeLy</strong></p>
        <p class="title2"><em> A stylish way to view your media</em></p>
        <div style="text-align:center;">
            <button type="button" class="btn btn-primary">Movies</button>
            <button type="button" class="btn btn-primary btn-lg">Large button</button>
        </div>
    </body>
</html>

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

如果你使用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并使其依赖

如果代码看起来不错,请验证jQuery是否成功加载到服务器。在我的例子中,jQuery文件是由我的IDE发布到服务器的,但是web服务器只有一个0 KB的文件存根。由于没有内容,服务器无法将文件提供给浏览器。

在重新发布文件并验证服务器实际上接收了整个文件后,我的网页不再向我提供错误。

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

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