-2

可能重复:
我可以在同一页面上使用多个版本的 jQuery 吗?

我正在使用 3 个 JQUery wordpress 插件,所以在我的 header.php 文件中,我有 3 个类似的 jquery 脚本(这对于使我的插件工作非常重要。

它们在这里:(在我的 header.php 中)

<script type="text/javascript" src="liquidcarousel/js/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

 <script src="http://mywebsite.com/price-filter-wid-css/jquery-1.8.2.js"></script>

这三个相互冲突并且输出不正确..那么,我怎样才能让我的插件工作..?


那么,我是否需要保持如下:

<script>
var jq142 = jQuery.noConflict();
</script>
<script>
var jq142 = jQuery.noConflict();
</script>
<script>
var jq182 = jQuery.noConflict();
</script>


上面有什么问题???


这是我的其他代码:

$(document).ready(function() {
            $('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
        });


$(function() {
        $( "#makeup" ).slider({
            range: true,
            min: 0,
            max: 500,
            values: [ 0, 500 ],
            slide: function( event, ui ) {
            $( "#minprice" ).val( ui.values[ 0 ] );     
            $( "#maxprice" ).val( ui.values[1 ] );  
            $( "#pricego" ).val( ui.values[0]+'-'+ui.values[1] );
        }

        });

    });

那么,我怎样才能正确使用上述功能,以避免这些 jquery 冲突..?


正如你所说,我已更改如下:

$(function() {
        mywebsite( "#makeup" ).slider({
            range: true,
            min: 0,
            max: 500,
            values: [ 0, 500 ],
            slide: function( event, ui ) {
            $( "#minprice" ).val( ui.values[ 0 ] );     
            $( "#maxprice" ).val( ui.values[1 ] );  
            $( "#pricego" ).val( ui.values[0]+'-'+ui.values[1] );
        }

        });

    });


$(document).ready(function() {
            liquidcarousel('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
        });


请纠正我,如果我错了...



完成所有更改后,这是我的代码:(但仍然没有得到输出)

<!-- Liquidcarousel Stuff  -->
<link type='text/css' rel='stylesheet' href='liquidcarousel/css/style.css' />
<link type='text/css' rel='stylesheet' href='liquidcarousel/css/liquidcarousel.css' />
<script type="text/javascript" src="liquidcarousel/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
     var liquidcarousel = $.noConflict(true);
     </script>
<script type="text/javascript" src="liquidcarousel/js/jquery.liquidcarousel.pack.js"></script>
<script type="text/javascript">

        $(document).ready(function() {
            liquidcarousel('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
        });

        $(document).ready(function() {
            liquidcarousel('#liquid2').liquidcarousel({height:129, duration:100, hidearrows:false});
        });

</script>



<!-- Categories Display Widget Stuff   -->
<link href="http://mywebsite.com/cat-wid-css/css/dcaccordion.css" rel="stylesheet" type="text/css" />
<link href="http://mywebsite.com/cat-wid-css/css/skins/blue.css" rel="stylesheet" type="text/css" />
<link href="http://mywebsite.com/cat-wid-css/css/skins/graphite.css" rel="stylesheet" type="text/css" />
<link href="http://mywebsite.com/cat-wid-css/css/skins/grey.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
       var googleapis = $.noConflict(true);
     </script>
<script type='text/javascript' src='http://mywebsite.com/cat-wid-css/js/jquery.cookie.js'></script>
<script type='text/javascript' src='http://mywebsite.com/cat-wid-css/js/jquery.hoverIntent.minified.js'></script>
<script type='text/javascript' src='http://mywebsite.com/cat-wid-css/js/jquery.dcjqaccordion.2.7.min.js'></script>
<script type="text/javascript">
$(document).ready(function($){

                    googleapis('.accordion-6').dcAccordion({
                        eventType: 'hover',
                        autoClose: true,
                        saveState: true,
                        disableLink: true,
                        menuClose: false,
                        speed: 'medium',
                        showCount: true,

                        autoExpand: true,
                        cookie  : 'dcjq-accordion-1',
                        classExpand  : 'dcjq-current-parent',

                        menuClose: false    
                    });

});
</script>







<!-- Price Filter Display Widget Stuff   -->
    <link rel="stylesheet" href="http://mywebsite.com/price-filter-wid-css/themes/base/jquery.ui.all.css">
    <script src="http://mywebsite.com/price-filter-wid-css/jquery-1.8.2.js"></script>
     <script type="text/javascript">
           var mywebsite = $.noConflict(true);
       </script>
    <script src="http://mywebsite.com/price-filter-wid-css/ui/jquery.ui.core.js"></script>
    <script src="http://mywebsite.com/price-filter-wid-css/ui/jquery.ui.widget.js"></script>
    <script src="http://mywebsite.com/price-filter-wid-css/ui/jquery.ui.mouse.js"></script>
    <script src="http://mywebsite.com/price-filter-wid-css/ui/jquery.ui.slider.js"></script>
    <link rel="stylesheet" href="http://mywebsite.com/price-filter-wid-css/demos.css">
    <style>
    #demo-frame > div.demo { padding: 10px !important; };
    </style>

    <script>


    mywebsite(function() {
        mywebsite( "#makeup" ).slider({
            range: true,
            min: 0,
            max: 500,
            values: [ 0, 500 ],
            slide: function( event, ui ) {
            mywebsite( "#minprice" ).val( ui.values[ 0 ] );     
            mywebsite( "#maxprice" ).val( ui.values[1 ] );  
            mywebsite( "#pricego" ).val( ui.values[0]+'-'+ui.values[1] );
        }

        });

    });





    </script>

我仍然没有得到输出..请告诉我还是出了什么问题..?...

4

1 回答 1

0
 <script type="text/javascript" src="liquidcarousel/js/jquery-1.4.2.min.js"></script>
     <script type="text/javascript">
     var someName = $.noConflict(true);
     </script>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
     <script type="text/javascript">
       var googleapis = $.noConflict(true);
     </script>

   <script src="http://mywebsite.com/price-filter-wid-css/jquery-1.8.2.js"></script>
      <script type="text/javascript">
           var mywebsite = $.noConflict(true);
       </script>

然后,而不是$('#selector').function();,你会做someName('#selector').function();or googleapis('#selector').function();ormywebsite('#selector').function();以避免冲突。

而不是$必须使用someNameorgoogleapis或者mywebsite你需要的任何东西

$(document).ready(function() {
           // $('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false});
            googleapis('#liquid1').liquidcarousel({height:129, duration:100, hidearrows:false}); //if you need to use googleapis jquery version in that case
        });


someName(function() {
        someName( "#makeup" ).slider({ // if you need liquidcarousel to use in this case
            range: true,
            min: 0,
            max: 500,
            values: [ 0, 500 ],
            slide: function( event, ui ) {
            someName( "#minprice" ).val( ui.values[ 0 ] );     
            someName( "#maxprice" ).val( ui.values[1 ] );  
            someName( "#pricego" ).val( ui.values[0]+'-'+ui.values[1] );
        }

        });

    });
于 2012-10-05T00:07:53.213 回答