【问题标题】:How Can I remove Conflict in my Jquery?如何在我的 Jquery 中删除冲突?
【发布时间】:2011-12-30 06:02:46
【问题描述】:

我是 JQuery 新手,我在我的页面中使用了 2 个 jQuery。

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

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

现在,当我像这样使用第二个 jQuery 时,我丢失了我的第一个 jQuery。无法加载

 <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 进行图像滑动。谁能告诉我问题是什么?谢谢

【问题讨论】:

    标签: jquery-ui jquery jquery-plugins jquery-selectors


    【解决方案1】:

    这是你的第二个 jQuery 脚本,你应该在上面执行$.noConflict()

    如果你这样做了;

    <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 后再次运行 $.noConflictjQuery 将引用 1.4,但 $ 将是未定义的。

    但是,如果你这样做:

    <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 变量也是如此)。

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

    <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

    【讨论】:

      猜你喜欢
      • 2015-11-21
      • 2017-03-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多