![](/img/trans.png)
[英]unexpected token error '<' on jquery.min.js and bootstrap.js
[英]jquery.min.js is it needed? bootstrap-4.0.0-alpha.6
下載“源代碼”后,我最近一直在使用 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 final 於幾周前發布。
是的,導航欄需要 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 的源代碼,您會發現 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 已過時,並且最新版本的 Bootstrap 4 中的 jQuery 依賴項沒有改變,盡管它現在還需要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)');
}
...
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.