jquery.min.js需要吗? bootstrap-4.0.0-alpha.6

jquery.min.js is it needed? bootstrap-4.0.0-alpha.6

我最近在下载 'source'.

后一直在摆弄 bootstrap-4.0.0-alpha.6

一些示例主题 'bootstrap-4.0.0-alpha.6\bootstrap-4.0.0-alpha.6\docs\examples' 有这个脚本(特别是 navbar-top-fixed)

<script>window.jQuery || document.write('<script src="../../assets/js/vendor/jquery.min.js"><\/script>')</script>

我正在尝试将示例主题 'navbar-top-fixed' 移动到其他位置,因此我也在移动关联的脚本并更新路径。

我在任何地方都找不到这个文件吗?

用过吗?

assets/js/vendor 路径显示 jquery-slim 但不是 jquery.min

Bootstrap-4.0.0-alpha.6 已过时。

Bootstrap 4.0.0 最终版本于几周前发布。

是的,导航栏需要 jQuery。

您可以使用以下内容作为入门模板:

<!doctype html>
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Hello, world!</title>
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>

参考:

https://getbootstrap.com/docs/4.0/getting-started/introduction/

如果您查看 Bootstrap 4 Alpha 的 JavaScript 的 the source code,您会发现 jQuery 确实被列为要求:

if (typeof jQuery === 'undefined') {
  throw new Error('Bootstrap\'s JavaScript requires jQuery. jQuery must be included before Bootstrap\'s JavaScript.')
}

+function ($) {
  var version = $.fn.jquery.split(' ')[0].split('.')
  if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1) || (version[0] >= 4)) {
    throw new Error('Bootstrap\'s JavaScript requires at least jQuery v1.9.1 but less than v4.0.0')
  }
}(jQuery);

具体来说,Bootstrap 要求 jQuery 版本至少为 1.9.1,但低于 4.0.0。

请注意 Bootstrap 4 Alpha 已过时,jQuery 依赖项 hasn't changed in the latest version of Bootstrap 4, though it now additionally requires Popper.js:

if (!this._inNavbar) {
  /**
   * Check for Popper dependency
   * Popper - https://popper.js.org
   */
  if (typeof Popper === 'undefined') {
    throw new TypeError('Bootstrap dropdown require Popper.js (https://popper.js.org)');
  }
...

希望对您有所帮助!