同一页面上的两个jQuery版本 [英] Two jQuery versions on the same page

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

问题描述

是否可以在同一个文档中使用2个不同的jQuery版本,并让它们不相互冲突?

Is it possible to have 2 different jQuery versions in the same document, and have them to not collide with each other?

例如,如果我创建了一个bookmarklet,想要将代码基于jQuery。
这个bookmarklet注入了一些使用另一个版本的jQuery的页面,然后我的代码将覆盖页面上使用的版本。

For example if I create a bookmarklet and want to base the code on jQuery. This bookmarklet is injected on some page that uses another version of jQuery then my code would overwrite the version used on the page.

是否可以避免这种情况?
或者是否有其他一些提供此功能的库
或许我应该重新考虑整个事情。

Is it possible to avoid that? Or are there some other libraries that provides this functionality Or maybe I should rethink the whole thing.

感谢您的答案和指示,

bob

推荐答案

jQuery提供了一种避免冲突的方法。加载第一个版本后,可以将其分配给另一个变量。

jQuery comes with a way to avoid collisions. After you load the first version, you can assign it to a different variable.

var $j = jQuery.noConflict();

然后加载你的第二个jQuery版本。您加载的第一个可以使用$ j(...)访问,而第二个可以使用$(...)访问。

And then load your second jQuery version. The first one you load can be accessed with $j(...) while the second one can be accessed with $(...).

或者,有人制作小帮手,试图让您更容易在不同版本之间切换。

Alternatively, somebody made a little helper in an attempt to make it easier to switch between different versions.

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

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