jquery脚本标签冲突

时间:2012-10-04 23:46:10

标签: jquery

  

可能重复:
  Can I use multiple versions of jQuery on the same page?

我使用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>

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

1 个答案:

答案 0 :(得分: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();googleapis('#selector').function();mywebsite('#selector').function();来避免冲突。

而不是$必须使用someNamegoogleapismywebsite,无论您需要什么

$(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] );
        }

        });

    });