Bootstrap 3.3.6 JQuery 2.2.4版本异常 [英] Bootstrap 3.3.6 JQuery 2.2.4 Version Exception

查看:57
本文介绍了Bootstrap 3.3.6 JQuery 2.2.4版本异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在新的ASP.Net Core应用程序中使用Bootstrap和JQuery.但是在尝试运行应用程序时遇到错误"Bootstrap的JavaScript需要jQuery 1.9.1或更高版本,但低于3版".

我已经使用Bower将Bootstrap添加到我的应用程序中,并添加了Bootstrap版本3.3.6,该版本会自动添加JQuery 2.2.4.问题在于,似乎JQuery的2.2.4版本实际上是在3.0.0-rc1上版本,这会导致Bootstrap验证失败,因为它仅接受1.9.1版本但低于3版本的JQuery版本? >

如何解决此冲突? Bootstrap如何与不兼容的JQuery版本打包在一起?

在这里您可以在解决方案中看到我的文件,其中显示了Bootstrap和JQuery版本:如您所见,也没有安装其他版本的JQuery.

这是我的HTML标记的摘录

 <html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
</head>
<body>
    <h1>HELLOOOO!</h1>
    <script type="text/javascript" src="~/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
</body>

</html> 

这会导致Chrome报告"Bootstrap的JavaScript需要jQuery 版本1.9.1或更高版本,但低于版本3"

任何帮助将不胜感激!

解决方案

我们发现问题的根源是C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git中的git.exe,它不是真正的Git,而是某种包装.

使用它,bower会尝试安装正确的版本,但是如果您查看bower缓存,您会发现实际下载的文件不匹配.

示例:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External>

bower install jquery#2.2.4
bower jquery#2.2.4          not-cached https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             resolve https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4            checkout 2.2.4
bower jquery#2.2.4            resolved https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             install jquery#2.2.4

jquery#2.2.4 bower_components\jquery

检查%USERPROFILE%\ AppData \ Local \ bower \ cache \ packages \ 35300e45e44dbc6f186ed069533ef0af \ 2.2.4 \ dist \ jquery.js"的内容:

/*eslint-disable no-unused-vars*/
/*!
 * jQuery JavaScript Library v3.1.0

解决方案:

  1. 安装适用于Windows的Git
  2. 删除%USERPROFILE%\ AppData \ Local \ bower
  3. 重新启动Visual Studio
  4. 删除wwwroot/lib并还原Bower软件包

更新:您可能还需要

I have used bower to add Bootstrap to my application, and have added version 3.3.6 of Bootstrap which automatically adds JQuery 2.2.4. The problem is that it seems that version 2.2.4 of JQuery is actually versioned at 3.0.0-rc1, which causes Bootstrap validation to fail as it will only accept versions of JQuery from version 1.9.1 but less than version 3?

How can I resolve this conflict? How is it that Bootstrap comes packaged with an incompatible version of JQuery?

Here you can see my files in my solution, showing the Bootstrap and JQuery versions: as you can see there are no other versions of JQuery installed either.

Here is a snippet of my Html markup

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
</head>
<body>
    <h1>HELLOOOO!</h1>
    <script type="text/javascript" src="~/lib/jquery/dist/jquery.min.js"></script>
    <script type="text/javascript" src="~/lib/bootstrap/dist/js/bootstrap.min.js"></script>
</body>

</html>

Which results in Chrome reporting "Bootstrap's JavaScript requires jQuery version 1.9.1 or higher, but lower than version 3"

Any help would be greatly appreciated!

解决方案

We found that the root of the problem is git.exe from C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git which is not a real Git but some sort of a wrapper.

With it, bower tries to install correct versions, but if you look into the bower cache you can see that actual downloaded files don't match.

Example:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External>

bower install jquery#2.2.4
bower jquery#2.2.4          not-cached https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             resolve https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4            checkout 2.2.4
bower jquery#2.2.4            resolved https://github.com/jquery/jquery-dist.git#2.2.4
bower jquery#2.2.4             install jquery#2.2.4

jquery#2.2.4 bower_components\jquery

Check the contents of "%USERPROFILE%\AppData\Local\bower\cache\packages\35300e45e44dbc6f186ed069533ef0af\2.2.4\dist\jquery.js":

/*eslint-disable no-unused-vars*/
/*!
 * jQuery JavaScript Library v3.1.0

Solution:

  1. Install Git for Windows
  2. Delete %USERPROFILE%\AppData\Local\bower
  3. Restart Visual Studio
  4. Delete wwwroot/lib and Restore bower packages

Update: You might also need to adjust VS external web tools settings

这篇关于Bootstrap 3.3.6 JQuery 2.2.4版本异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆