zoukankan      html  css  js  c++  java
  • 在同一个页面使用多个不同的jQuery版本,让它们并存而不冲突

    jQuery自诞生以来,版本越来越多,而且jQuery官网的新版本还在不断的更新和发布中,现已经达到了1.6.4版本,但是我们在以前的项目中就已经使用了旧版本的jQuery,比如已经出现的:1.3.X、1.4.X、1.5.X、1.6.2等等。

      由于项目的需要,必然也需要不断的使用较新版的jQuery,但对于原来就已经存在并已经采用了的旧jQuery版本,我们如何让多个不同的jQuery版本在同一个页面并存而不冲突呢?

      其实,利用jQuery.noConflict()特性,我们不仅可以让jQuery与其他的JS库并存,比如Prototype。也可以与jQuery本身的其他不同版本并存而不冲突。

    复制代码
     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    2 <html>
    3 <head>
    4 <title>在同一个页面中加载多个不同的jQuery版本</title>
    5 <!-- 从谷歌服务器加载jQuery最新版本 -->
    6 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js"></script>
    7 <script type="text/javascript">
    8 var jQuery_New = $.noConflict(true);
    9 </script>
    10 <!-- 加载jQuery1.6.2版本 -->
    11 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    12 <script type="text/javascript">
    13 var jQuery_1_6_2 = $.noConflict(true);
    14 </script>
    15 <!-- 加载jQuery1.5.2版本 -->
    16 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
    17 <script type="text/javascript">
    18 var jQuery_1_5_2 = $.noConflict(true);
    19 </script>
    20 <!-- 加载jQuery1.4.2版本 -->
    21 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    22 <script type="text/javascript">
    23 var jQuery_1_4_2 = $.noConflict(true);
    24 </script>
    25 <!-- 加载jQuery1.3.2版本 -->
    26 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
    27 <script type="text/javascript">
    28 var jQuery_1_3_2 = $.noConflict(true);
    29 </script>
    30 <script type="text/javascript">
    31 alert(jQuery_New.fn.jquery);
    32 alert(jQuery_1_6_2.fn.jquery);
    33 alert(jQuery_1_5_2.fn.jquery);
    34 alert(jQuery_1_4_2.fn.jquery);
    35 alert(jQuery_1_3_2.fn.jquery);
    36
    37 jQuery_New(function($){$('<p>我是最新的'+$.fn.jquery+'版本添加进来的。</p>').appendTo('body');});
    38 jQuery_1_6_2(function($){$('<p>我是'+$.fn.jquery+'版本添加进来的。</p>').appendTo('body');});
    39 jQuery_1_5_2(function($){$('<p>我是'+$.fn.jquery+'版本添加进来的。</p>').appendTo('body');});
    40 jQuery_1_4_2(function($){$('<p>我是'+$.fn.jquery+'版本添加进来的。</p>').appendTo('body');});
    41 jQuery_1_3_2(function($){$('<p>我是'+$.fn.jquery+'版本添加进来的。</p>').appendTo('body');});
    42 </script>
    43 </head>
    44 <body>
    45 在同一个页面中加载多个不同的jQuery版本
    46 <br>
    47 </body>
    48 </html>
  • 相关阅读:
    C#2.0新特性
    .NET Framework 4.5新特性
    C#4.0 中的新特性
    C#3.0中的新特性
    开始使用Mac OS X——写给Mac新人
    关于WF4 State Machine 状态机工作流的发布问题.
    C# 3.5新特性
    libssh2编译错误(configure error: cannot find OpenSSL or Libgcrypt)解决方法
    程序员转产品经理的思考
    升级PHP版本
  • 原文地址:https://www.cnblogs.com/chenbg2001/p/4297050.html
Copyright © 2011-2022 走看看