简体   繁体   English

使用其他版本的jQuery加载插件

[英]Loading a plugin with a different version of jQuery

I'm trying to run a plugin on CS Cart site which only allows jQuery 1.7+ http://owlgraphic.com/owlcarousel/ is the plugin i'm using. 我正在尝试在CS Cart网站上运行一个插件,该插件仅允许jQuery 1.7+ http://owlgraphic.com/owlcarousel/是我正在使用的插件。

I've found a snippet of code on another ticket, which allows to run two version of jQuery using the noConflict method. 我在另一张票据上找到了一段代码,该代码允许使用noConflict方法运行两个版本的jQuery。 All of the original code is running fine. 所有原始代码都运行良好。 But this plugin is not running and it keeps throwing the error Uncaught TypeError: undefined is not a function on this line: $j("#wrapper").owlCarousel({ However if I add the following lin inside my document on load function it seems to run, then breaks when it gets to the .owlCarousel function. - $j('body').css('background-color', 'red'); 但是此插件未运行,并且不断抛出错误Uncaught TypeError: undefined is not a function此行上TypeError: undefined is not a function$j("#wrapper").owlCarousel({但是,如果我在加载函数的文档中添加以下lin, - $j('body').css('background-color', 'red');似乎正在运行,然后在到达.owlCarousel函数时中断$j('body').css('background-color', 'red');

Here is a breakdown of my code: 这是我的代码细分:

//Loaded n at the top of the page //在页面顶部加载n

{script src="lib/js/jquery/jquery.min.js"}
{script src="lib/js/jquery/jquery.min.1.8.js"}

<script>var $j = jQuery.noConflict(true);</script>
    <script type='text/javascript'>
      $(document).ready(function(){
       console.log($().jquery); // This prints v1.5.2
       console.log($j().jquery); // This prints v1.8
      });
   </script>

//Loaded in lower down the page, after most of the existing JS //在大多数现有JS之后加载到页面下方

<script type='text/javascript'>
$j(document).ready(function(){
   $j('body').css('background-color', 'red');

$j("#wrapper").owlCarousel({

        //autoPlay: 3000, //Set AutoPlay to 3 seconds

        items : 2,
       itemsCustom : [
          [200, 2],

        ],
        navigation : true
    });

});

</script>

The strange thing is, if i replace the old version of jQuery with the new one, it works, but breaks all the old code that relies on the old version. 奇怪的是,如果我用新版本替换旧版本的jQuery,它可以工作,但会破坏所有依赖旧版本的旧代码。

I hope I've provided enough info. 希望我提供了足够的信息。

Thanks in advance. 提前致谢。

jQuery plugins normally hooks to the current jquery version attached to it, first load the old jquery version then the plugin that will be using it then, load the newer one. jQuery插件通常会钩接到与其关联的当前jquery版本,首先加载旧的jquery版本,然后加载将要使用的插件,然后加载较新的版本。

I believe that the "plugin1" will be attached to the older version of jquery. 我相信“ plugin1”将附加到旧版本的jquery。

{script src="lib/js/jquery/jquery.min.js"}
<script>var j1 = jQuery.noConflict(true);</script>
{script src="lib/js/jquery/plugin1.js"}

{script src="lib/js/jquery/jquery.min.1.8.js"}
<script>var j2 = jQuery.noConflict(true);</script>
{script src="lib/js/jquery/plugin2.js"}
{script src="lib/js/jquery/plugin3.js"}

sorry for my english. 对不起我的英语不好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM