Bootstrap 的 JavaScript 需要 jQuery 1.9.1 或更高版本,但低于版本 3

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/37936751/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 20:53:38  来源:igfitidea点击:

Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3

javascriptjquerytwitter-bootstrap-3

提问by Suhail Mumtaz Awan

Introduction

介绍

I am working with the bootstrap framework.I am currently working on "Bootstrap Tabs"(hide/show).I am using bootstrap version 3 and jquery version 3.0.2 something.

我正在使用引导程序框架。我目前正在研究“引导程序选项卡”(隐藏/显示)。我正在使用引导程序版本 3 和 jquery 版本 3.0.2。

Problem

问题

My tabs are not working, unless i load jquery of version less than 1.6.But then ajax making problem with jquery less than 1.6. Chrome console give me this error.

我的选项卡不起作用,除非我加载版本低于 1.6 的 jquery。但是 ajax 使 jquery 低于 1.6 出现问题。Chrome 控制台给我这个错误。

bootstrap.min.js:6 Uncaught Error: Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3

bootstrap.min.js:6 未捕获错误:Bootstrap 的 JavaScript 需要 jQuery 1.9.1 或更高版本,但低于版本 3

I tried different fallback techniques but couldn't implement correctly.

我尝试了不同的回退技术,但无法正确实施。

I am stuck here for 2 days, if someone have any idea or any reference, please do help.Thanks for your time.

我在这里被困了 2 天,如果有人有任何想法或任何参考,请帮忙。感谢您的时间。

采纳答案by Irvin Dominin

Currently Bootstrap 3.x does not support jQuery 3.x as reported here: https://github.com/twbs/bootstrap/issues/16834

目前 Bootstrap 3.x 不支持 jQuery 3.x,如此处报道:https: //github.com/twbs/bootstrap/issues/16834

The issue is caused by:

问题是由以下原因引起的:

jQuery 3 is more strict than jQuery 2. It's like XHTML and HTML. Backward compatibility is preserved and code doesn't look like a mess. If I'm not mistaken, all you need to do is replace show() and hide() functions with .css('display', '') or addClass('hidden') and fix a selector in alert.js (QUnit fails on this line because $('#') is invalid in jQuery 3)

jQuery 3 比 jQuery 2 更严格。它就像 XHTML 和 HTML。向后兼容性得以保留,代码看起来不会一团糟。如果我没记错的话,您需要做的就是将 show() 和 hide() 函数替换为 .css('display', '') 或 addClass('hidden') 并修复 alert.js 中的选择器(QUnit在这一行失败,因为 $('#') 在 jQuery 3 中无效)

It is fixed in the Bootstrap 3.3.7 release: https://github.com/twbs/bootstrap/issues/16834#issuecomment-225039913

它在 Bootstrap 3.3.7 版本中得到修复:https: //github.com/twbs/bootstrap/issues/16834#issuecomment-225039913

回答by aleor

Latest current version of Bootstrap (3.3.7) now supports jQuery 3+, as per developer's comment here https://github.com/twbs/bootstrap/issues/16834.

最新版本的 Bootstrap (3.3.7) 现在支持 jQuery 3+,根据这里的开发人员评论https://github.com/twbs/bootstrap/issues/16834

回答by Tsutomu

If you use Bower to manage your javascript packages, to exclude jquery 3.0 you should specify the version of jquery like:

如果您使用 Bower 管理您的 javascript 包,要排除 jquery 3.0,您应该指定 jquery 的版本,例如:

"jquery": "^2.2"

in your bower.json.

在您的bower.json.

The bower.jsonof jquery-uipackage has a following line:

所述bower.jsonjquery-ui包装具有以下线:

"jquery": ">=1.6"

Because of it Bower installs the latest version of jQuery, which causes your problem.

因此,Bower 安装了最新版本的 jQuery,这会导致您的问题。

Note that jQuery 3.0 is released as of June 9, 2016.

请注意,jQuery 3.0 于 2016 年 6 月 9 日发布。

回答by Suhail Mumtaz Awan

What solved my problem is actually loading jquery lower version before bootstrap.js and then loading jquery higher version after bootstrap.js to resolve conflicts.Above is my example

解决我的问题实际上是在 bootstrap.js 之前加载 jquery 较低版本,然后在 bootstrap.js 之后加载 jquery 较高版本以解决冲突。 以上是我的例子

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="~/App_Theme/bootstrap/js/bootstrap.min.js"></script>
<script>
    var $j = jQuery.noConflict();
</script>

<script src="http://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
<script>
    var $ = jQuery.noConflict();
</script>

回答by Yuriy Ivanochko

As for me, everything simple. It's all about queue links files. I need to move links like this:

至于我,一切都很简单。这都是关于队列链接文件的。我需要移动这样的链接:

<head>
     <script src="js/jquery1.9.1.js"></script>
     <script src="js/bootstrap.js"> </script>       
</head>

After all - it's working prorerly.

毕竟 - 它工作正常。

回答by Mohsen Abdollahi

I had same problem and I have not jquery 1.8.2 in my web pages.I solve my problem by change version of jquery in packages.config

我有同样的问题,我的网页中没有 jquery 1.8.2。我通过在packages.config 中更改 jquery 版本来解决我的问题

change

改变

  <package id="AspNet.ScriptManager.jQuery" version="1.8.2" targetFramework="net45" />
 <package id="jQuery" version="1.8.2" targetFramework="net45" />

to

<package id="AspNet.ScriptManager.jQuery" version="2.1.4" targetFramework="net45" />
 <package id="jQuery" version="2.1.4" targetFramework="net45" />

my jquery version is 2.1.4

我的 jquery 版本是2.1.4

回答by Chad

So I had the new version of Bootstrap but for some reason the min version was still the old version which did not support the JQuery 3. I removed the minified bootstrap JS then reminified the new Bootstrap.js and deployed and the problem went away.

所以我有了新版本的 Bootstrap,但由于某种原因,min 版本仍然是不支持 JQuery 3 的旧版本。我删除了缩小的 bootstrap JS,然后重新缩小了新的 Bootstrap.js 并部署,问题就消失了。