简体   繁体   English

附加Jquery.min.js时发生jQuery冲突

[英]Jquery conflict while attaching Jquery.min.js

I presume the is cause to my problem is a Jquery conflict. 我认为是我的问题的原因是Jquery冲突。 Please correct me in the first place if it isn't the case looking at below. 如果不是下面的情况,请首先纠正我。

I'm new to Jquery and trying to insert a drop down plug in to a site. 我是Jquery的新手,正在尝试将下拉插件插入网站。 The attempt is successful, however an already existing Jquery image slider goes away when the drop down works. 尝试成功,但是当下拉列表起作用时,已经存在的Jquery图像滑块将消失。

My code looks like below. 我的代码如下所示。

Links which relevant to the image slider plug in: 与图像滑块相关的链接插入:

<script src="css/SliderOne/jquery.min.js"></script>
<script src="css/SliderOne/jquery.pepperk.js"></script>

<script>
$(window).load(function() {
$('.blueberry').blueberry();
});
</script>

and the links for the dropdown plugin; 以及下拉插件的链接;

<script src="pro_v/jqueryminx.js"></script>
<script src="js/homedrop/jqueryx.selectric.js"></script>
<script>
$(function(){
    $('select, .select').selectric();

    $('.customOptions').selectric({
        optionsItemBuilder: function(itemData, element, index){
            return element.val().length ? '<span class="ico ico-' + element.val() +  '">    </span>' + itemData.text : itemData.text;
        }
    });
});
</script>

When I remove the jqueryminx.js link the image slider works fine. 当我删除jqueryminx.js链接时,图像滑块工作正常。 So I tried doing the following as suggested by one of the stakoverflow questions but couldn't get to work. 因此,我尝试按照stakoverflow问题之一的建议进行以下操作,但无法正常工作。

My attempt as follows. 我的尝试如下。 tried to use noConflict; 试图使用noConflict;

<script src="css/SliderOne/jquery.min.js"></script>
$.noConflict(true);
<script src="css/SliderOne/jquery.pepperk.js"></script>

<script>
$(window).load(function() {
$('.blueberry').blueberry();
});
</script>

and also here. 还有这里

<script src="pro_v/jqueryminx.js"></script>
$.noConflict(true);
<script src="js/homedrop/jqueryx.selectric.js"></script>
<script>
$(function(){
    $('select, .select').selectric();

    $('.customOptions').selectric({
        optionsItemBuilder: function(itemData, element, index){
            return element.val().length ? '<span class="ico ico-' + element.val() +  '">        </span>' + itemData.text : itemData.text;
        }
    });
});
</script>

Doesn't seems to be working. 似乎没有用。 Any help would be much appreciated. 任何帮助将非常感激。 Thank you. 谢谢。

To properly apply noConflict you should put noConflict into the script tags. 要正确应用noConflict,您应该将noConflict放入脚本标签中。 it will clear $ variable from global scope. 它将从全局范围清除$变量。 You will then reference jquery via jQuery. 然后,您将通过jQuery引用jquery。

<script src="css/SliderOne/jquery.min.js"></script>
<script src="css/SliderOne/jquery.pepperk.js"></script>

<script>
$.noConflict(true);
jQuery(window).load(function() {
jQuery('.blueberry').blueberry();
});
</script>

OR you can use this in this contruct using $ variable internal to ready callback function 或者,您可以在此构造函数中使用此函数,使用准备好回调函数的$变量

jQuery( document ).ready(function( $ ) {
  // Code that uses jQuery's $ can follow here. In your case
 $('.blueberry').blueberry();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM