如果你包含三个版本的jquery并且在中间包含一个使用jquery $对象的脚本会发生什么

Mas*_*asu 2 javascript jquery interpreter compilation

我遇到过一个问题,即我的多个插件在他们的jquery版本上存在冲突.现在我搜索了谷歌,我知道你应该最终只使用一个版本的jquery并将你的代码更新到该版本的jquery.但是,出于好奇,我很想知道当你执行以下操作时会发生什么:

<include latest jquery>
<include script that uses jquery>  <---and this jquery code is called back or triggered in some event handler function.. what happens then? what jquery $ version is used? the last jquery object that was added (the 'yet another version of jquery' )
<include some other version of jquery>
<include yet another version of jquery>
Run Code Online (Sandbox Code Playgroud)

使用什么版本的jquery?为什么?究竟发生了什么,每个脚本的加载和执行是如何发生的?它只是调用最新的jquery的$别名?谢谢您的帮助.

Pas*_*cle 6

你可以使用jQuery.noConflict()来拥有多个版本的jQuery.只有一个人会使用$.

例如

<script src='jquery-1.3.2.js'></script>
<script>
var jq132 = jQuery.noConflict();
</script>
<script src='jquery-1.4.2.js'></script>
<script>
var jq142 = jQuery.noConflict();
</script>
Run Code Online (Sandbox Code Playgroud)

然后你可以使用jq142和jq132.更多详情http://api.jquery.com/jQuery.noConflict/