如何在Jquery中删除冲突?

Sco*_*ion 1 jquery jquery-ui jquery-plugins jquery-selectors

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

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

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

现在,当我使用第二个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>
Run Code Online (Sandbox Code Playgroud)

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

Mat*_*att 6

这是你应该执行的第二个 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>
Run Code Online (Sandbox Code Playgroud)

双方jQuery$会指向jQuery的1.4,并没有将引用的jQuery 1.7.顺便说一句,如果你在加载jQuery 1.4之后$.noConflict 再次运行,jQuery将引用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>
Run Code Online (Sandbox Code Playgroud)

$将指向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>
Run Code Online (Sandbox Code Playgroud)

那么无论是$jQuery将指向jQuery的1.7,只有你的jq变量指向的jQuery 1.4