【发布时间】:2010-05-14 20:20:08
【问题描述】:
注意:我知道 here 和 here 已经提出了类似的问题,但我正在寻找有关如何使这项工作或完全避免它的充分理由的更多说明。
我正在向已经使用旧版 jQuery 库 (1.1.3.1) 的现有网站添加功能。我一直在针对最新版本的 jQuery 库 (1.4.2) 编写我添加的功能。我只使用较新版本的 jQuery 测试了该网站,但它破坏了功能,所以现在我正在考虑在同一页面上使用这两个版本。这怎么可能?
我需要在我的代码中做什么来指定我使用的是一个版本的 jQuery 而不是另一个?例如,我会将两个版本的 jQuery 的 <script> 标签放在页面的标题中,但是我需要做什么才能在调用代码中确定我正在调用库的一个版本还是其他?
可能是这样的:
//Put some code here to specify a variable that will be using the newer
//version of jquery:
var $NEW = jQuery.theNewestVersion();
//Now when I use $NEW, I'll know it's the newest version and won't
//conflict with the older version.
$NEW('#personName').text('Ben');
//And when I use the original $ in code, or simply 'jquery', I'll know
//it's the older version.
$('#personName').doSomethingWithTheOlderVersion();
更新:在阅读了一些答案后,我开始怀疑尝试玩这个游戏是否是一个好主意......
【问题讨论】:
标签: javascript jquery