我如何运行在同一页上不同版本的jQuery? [英] How do I run different versions of jQuery on the same page?

查看:144
本文介绍了我如何运行在同一页上不同版本的jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我公司已经购买了呈现在页面上ASP.NET控件的产品。这种控制使用jQuery 1.2.3,并添加一个脚本标记到页面引用它。如果以任何方式(包括修改引用不同版本的jQuery)修改控件的开发人员将不支持使用控制。

My company has purchased a product that renders an ASP.NET control on the page. This control uses jQuery 1.2.3 and adds a script tag to the page to reference it. The developers of the control will not support use of the control if it modified in any way (including modification to reference a different version of jQuery).

我要开始我自己的控制发展,想使用的功能和jQuery 1.3的速度提升。这两个控件都需要在同一页面上。

I'm about to start development of my own control and would like to use the features and speed improvements of jQuery 1.3. Both of these controls will need to exist on the same page.

我怎样才能让购买的控制使用jQuery 1.2.3和新的定制开发使用jQuery 1.3?也出于好奇,如果我们是用一个需要引用的jQuery的另一个版本的额外控制?

How can I allow the purchased control to use jQuery 1.2.3 and new custom development to use jQuery 1.3? Also out of curiosity, what if we were to use an additional control that needed to reference yet another version of jQuery?

推荐答案

您可以通过在无冲突模式。 无冲突的模式是典型的解决方案,以得到的jQuery像原型的其他框架的网页上的工作,并且也可以在这里使用因为它基本上是jQuery的命名空间的每个版本你加载。

You can achieve this by running your version of jQuery in no-conflict mode. "No conflict" mode is the typical solution to get jQuery working on a page with other frameworks like prototype, and can be also be used here as it essentially namespaces each version of jQuery which you load.

<script src="jQuery1.3.js"></script>
<script>
    jq13 = jQuery.noConflict(true);
</script>

<!-- original author's jquery version -->
<script src="jQuery1.2.3.js"></script>

这一变化将意味着任何的jQuery的东西,你想用就需要使用被称为 jq13 ,而不是 $ ,例如:

jq13("#id").hide();

这不是有相同的页面上运行两个版本的理想情况,但如果你没有选择,那么上面的方法应该让你同时使用两种不同的版本。

It's not an ideal situation to have the two versions running on the same page, but if you've no alternative, then the above method should allow you to use two differing versions at once.

另外出于好奇,如果我们是使用一个额外的控制
      一个需要引用的jQuery的另一个版本?

Also out of curiosity, what if we were to use an additional control that needed to reference yet another version of jQuery?

如果您需要添加的jQuery的另一个版本,你可以在上面展开:

If you needed to add another version of jQuery, you could expand on the above:

<script src="jQuery1.3.js"></script>
<script>
    jq13 = jQuery.noConflict(true);
</script>
<script src="jQuery1.3.1.js"></script>
<script>
    jq131 = jQuery.noConflict(true);
</script>

<!-- original author's jquery version -->
<script src="jQuery1.2.3.js"></script>

变量 jq13 jq131 将分别用于您需要的特定版本的功能。

The variables jq13 and jq131 would each be used for the version-specific features you require.

重要的是,在原开发商使用了 jQuery是最后加载 - 原来的开发者可能会写自己的code中的假设下 $()将使用他们的jQuery的版本。如果以后他们加载另一个版本的 $ 将抓住的最后一个版本加载,这将意味着原开发商的code最新的库运行版本,渲染 noConflicts 有些多余!

It's important that the jQuery used by the original developer is loaded last - the original developer likely wrote their code under the assumption that $() would be using their jQuery version. If you load another version after theirs, the $ will be "grabbed" by the last version you load, which would mean the original developer's code running on the latest library version, rendering the noConflicts somewhat redundant!

这篇关于我如何运行在同一页上不同版本的jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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