用于Bootstrap和其他库文件的不同版本的jquery

问题描述:

我有一个仅支持Jquery 1.5的Javascript库,并且我有需要jQuery 1.8的前端(Bootstrap和其他此类库).

I have a Javascript library which only supports Jquery 1.5 and I have front end (Bootstrap and other such library) which require jQuery 1.8.

如何为不同的库文件使用两组jQuery?

How can I use two set of jquery for different library files?

我知道没有冲突,但是遇到了一些问题……

I am aware of no-conflict but facing some problem…

我必须先加载jQuery 1.5(有一些限制)…然后加载jQuery 1.8,然后加载需要jQuery 1.8的JavaScript库.然后我打电话给Jquery. jQuery.noConflict ..代码类似:

I have to load jQuery 1.5 first (some restriction)… then I load jQuery 1.8 then I load javascript library which require jQuery 1.8. Then I call Jquery. jQuery.noConflict.. Code is something similar:

 <script src="js/jquery.1.5.js"></script>
 <script src="js/jquery.1.8.js"></script>
 //I want bootstrap to use v 1.8
 <script src="bootstrap.js"></script>
 <script>
 var $jq1 = jQuery.noConflict(true);
 </script>
 //Now rest of program should use jQuery 1.5

这是有效的解决方案吗?

Is this a valid solution??

基于user3388636的回复

Edit 1: based on reply by user3388636

我看到一些使用jQuery而不是$ ....的库.我希望在这种情况下也可以使用?

I see some library using jQuery instead of $....I hope this works in that case also??

这应该工作吗?

<script type="text/javascript" src="js/jquery-1.5.js"></script>
<script type="text/javascript" src="js/lib-using-jq-1.5.js"></script>
<script type="text/javascript">
   var jQuery_1_5 = $.noConflict(true);
</script>

<script type="text/javascript" src="js/jquery-1.8.js"></script>
<script type="text/javascript" src="js/lib-using-jq-1.8.js"></script>
<script type="text/javascript">
  var jQuery_1_8 = $.noConflict(true);
</script>

我现在可以取消$值了吗?

Can i now set back $ value??

<script type="text/javascript">
   $ = jQuery_1_5.noConflict(true);
</script>

我希望它可以为您提供帮助-

I hope it can help you - http://blog.nemikor.com/2009/10/03/using-multiple-versions-of-jquery/

<!-- load jQuery 1.1.3 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.1.3.js"></script>
<script type="text/javascript" src="jquery.dimensions.min.js"></script>

<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_1_3 = $.noConflict(true);
</script>

<!-- load jQuery 1.3.2 -->
<script type="text/javascript" src="http://code.jquery.com/jquery-1.3.2.js"></script>

<!-- revert global jQuery and $ variables and store jQuery in a new variable -->
<script type="text/javascript">
var jQuery_1_3_2 = $.noConflict(true);
</script>