如何在Jquery中删除冲突? [英] How Can I remove Conflict in my Jquery?

查看:66
本文介绍了如何在Jquery中删除冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是JQuery的新手,并且在页面中使用了2个jQueries.

I am new to JQuery And I have used 2 jQueries in my page.

对于第一个JQuery,我的脚本是这样的:

For first JQuery my script is like this:

<script>
    var jq = $.noConflict();
    jq(function() {
         jq( "#my_tabs" ).tabs({
         event: "click" //click
         });            
    });
</script>

现在,当我使用第二个jQuery时,我丢失了第一个jQuery.无法加载

Now when I use a second jQuery like this I lost my first jQuery. It's unable to load

 <script type="text/javascript">
  $(document).ready(function () {
    $("#waterwheel-carousel-default").waterwheelCarousel();

    $("#waterwheel-carousel-higharch").waterwheelCarousel({
        startingWaveSeparation: -90,
        waveSeparationFactor: .7,
        centerOffset: 10,
        startingItemSeparation: 120,
        itemSeparationFactor: .9,
        itemDecreaseFactor: .75
    });

    $("#waterwheel-carousel-horizon").waterwheelCarousel({
        startingWaveSeparation: 0,
        centerOffset: 30,
        startingItemSeparation: 150,
        itemSeparationFactor: .7,
        itemDecreaseFactor: .75,
        opacityDecreaseFactor: 1,
        autoPlay: 1500
    });

    $("#waterwheel-carousel-flat").waterwheelCarousel({
        itemSeparationFactor: 1,
        itemDecreaseFactor: 1,
        waveSeparationFactor: 1,
        startingWaveSeparation: 0,
        startingItemSeparation: 280,
        centerOffset: 10,
        opacityDecreaseFactor: .3,
        autoPlay: 3000,
        edgeReaction: 'reverse'
    });

    $("#waterwheel-carousel-vertical").waterwheelCarousel({
        orientation: 'vertical',
        startingItemSeparation: 100,
        startingWaveSeparation: 40,
        autoPlay: 2000
    });

  });
</script>

我正在使用两个jQueries进行图像滑动..谁能告诉我是什么问题?谢谢

I am using both jQueries for image sliding.. Can anyone tell me what the problem is? Thanks

推荐答案

这是您应该执行的 2nd jQuery脚本

It is your 2nd jQuery script you should be performing $.noConflict() on.

如果这样做;

<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script>
    var jq = $.noConflict();
    jq(function() {
         jq( "#my_tabs" ).tabs({
         event: "click" //click
         });            
    });
</script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>

jQuery$都将指向jQuery 1.4,而没有任何内容将引用jQuery 1.7.顺便说一句,如果您要在加载jQuery 1.4后再次运行$.noConflict ,则jQuery将引用1.4,但$将是未定义的.

Both jQuery and $ will point to jQuery 1.4, and nothing will refer to jQuery 1.7. Incidentally, if you were to run $.noConflict again after loading jQuery 1.4, jQuery would reference 1.4, but $ would be undefined.

但是,如果您这样做:

<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>
<script>
    var jq = $.noConflict();
    jq(function() {
         jq( "#my_tabs" ).tabs({
         event: "click" //click
         });            
    });
</script>

$将引用jQuery 1.7,但是jQuery将指向jQuery 1.4(您的jq变量也将指向该变量).

The $ will refer to jQuery 1.7, but the jQuery will point to jQuery 1.4 (as will your jq variable).

您可能想看看$.noConflict(true);释放jQuery $变量;所以你可以做这样的事情;

You may want to look at the $.noConflict(true); which releases both the jQuery and $ variables; so you can do something like this;

<script src="http://code.jquery.com/jquery-1.7.js"></script>
<script src="http://code.jquery.com/jquery-1.4.js"></script>
<script>
    var jq = $.noConflict(true);
    jq(function() {
         jq( "#my_tabs" ).tabs({
         event: "click" //click
         });            
    });
</script>

然后$jQuery都将指向jQuery 1.7,只有jq变量将指向jQuery 1.4

Then both the $ and jQuery will point to jQuery 1.7, and only your jq variable will point to jQuery 1.4

这篇关于如何在Jquery中删除冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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