JQuery版本冲突
我正在尝试使用Nivo JQuery Slider(http://nivo.dev7studios.com/)和Scrollable Gallery(http://flowplayer.org/tools/demos/scrollable/index.html)。
现在我遇到了一个问题,基本上Nivo Slider使用这个JQuery库:
和Scrollable Gallery使用这个:
当两者都启用时,只有缩略图库工作(因为它的脚本导入是在nivo之后完成的),当启用1.42版本时只有Nivo可以工作,而当只启用1.2.5版本时,只有可滚动图库工作。
我该怎么办?
如果您不能为这两个插件使用单个jQuery文件,请使用此解决方案:
要使用jQuery 1.4.2,请将代码放在SEF(Self Executing Function)中,如下所示:
(function($){ //code using jQuery 1.4.2 //here the $variable will be the jQuery object of 1.4.2 })(jQuery_1_4_2)
对于jQuery 1.2.5,您可以直接使用$ variable。
更新:根据您的评论,以下是使用它的方式。
如果要使用jQuery 1.4.2,请使用jQuery_1_4_2对象
例如: jQuery_1_4_2("#abc").slider(options)
如果你想使用jQuery 1.2.5使用$或jQuery对象
例如: $("#abc").scrollable(options)
Jquery Tools网站表示,升级将在一个多月内完成,使其符合Jquery 1.6。
话虽这么说,有很多不同的方法可以给这只猫皮肤涂抹,而且大部分时间都不及时。 我一直在使用jQuery Infinite Carousel取得巨大成功。 它的外观和行为几乎完全相同,并且与最新版本的jQuery没有冲突。
你的post不清楚,但如果你这样做,我会避免加载两个不同版本的Jquery。 这是一个额外开销的TON,根本不能帮助你的网站。
简单地将这个java脚本代码复制并粘贴到“HEAD”标签中
// jquery版本冲突代码
var newJQuery = jQuery.noConflict(true), oldJQuery = jQuery; (function ($) { // code that needs 1.4.2 goes here }(newJQuery)); (function ($) { // code that needs 1.2.6 goes here }(oldJQuery)); // code that needs oldJQuery and newJQuery can go here
并看到它的工作110%…………………….. :)享受!!!