简体   繁体   English

来自 googleapis 的 jquery.min.js 与 1.6.2 jquery.min.js 冲突

[英]jquery.min.js conflicting with 1.6.2 jquery.min.js from googleapis

I'm using <script src="js/jquery.min.js"></script> FOR THE SLIDER and many other functionalities.我正在为 SLIDER 和许多其他功能使用<script src="js/jquery.min.js"></script> I'm also using <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script> FOR THE GALLERY.我也在使用<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>画廊。

Everything seems to work perfectly but when I add 1.6.2 jquery.min.js from googleapis it stops everything, including the sliders and the smooth scrolling.一切似乎都很完美,但是当我从 googleapis 添加 1.6.2 jquery.min.js 时,它会停止一切,包括滑块和平滑滚动。 The only thing that is working is the gallery.唯一有效的是画廊。

Here's my code:这是我的代码:

<link href="css/bootstrap.css" rel='stylesheet' type='text/css' />
<link rel="stylesheet" type="text/css" href="css/jquery.jscrollpane.css" media="all" />
<script src="js/jquery.min.js"></script>
<link href="css/style.css" rel='stylesheet' type='text/css' />
<script type="text/javascript" src="js/move-top.js"></script>
<script type="text/javascript" src="js/easing.js"></script>
<script type="text/javascript" src="js/jquery.flexisel.js"></script>
<script type="text/javascript">
        jQuery(document).ready(function($) {
            $(".scroll").click(function(event){     
                event.preventDefault();
                $('html,body').animate({scrollTop:$(this.hash).offset().top},1000);
            });
        });
    </script> 

In the body I have this code:在正文中,我有以下代码:

<script type="text/javascript" src="js/jquery.easing.1.3.js"></script>
<!-- the jScrollPane script -->
<script type="text/javascript" src="js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="js/jquery.contentcarousel.js"></script>
<script type="text/javascript">
$('#ca-container').contentcarousel();
</script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>

This is the one that's causing conflict, I have tried to put it in the head but it did not make any difference:这是引起冲突的原因,我试图把它放在头上,但没有任何区别:

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

Thank you for your assistance!谢谢您的帮助!

In general you should avoid using 2 different versions of jQuery on the same page. 通常,您应该避免在同一页面上使用2个不同版本的jQuery。 Most of the time you won't need to - they are largely backwards compatible. 大多数时候,您不需要-它们在很大程度上是向后兼容的。 Try putting the newer of the 2 versions of jQuery first, then removing the other one. 尝试先放置jQuery 2个版本中的较新版本,然后删除另一个。 As js/jquery.min.js is the newer version, try removing the google ajax apis one completely. 由于js/jquery.min.js是较新的版本,请尝试完全删除google ajax api。

If you are using something that is broken by a new version of jQuery, check that there hasn't been a new version of that thing released. 如果使用的东西被jQuery的新版本破坏,请检查是否尚未发布该东西的新版本。 If there hasn't, try to fix it yourself to work with the new jQuery. 如果没有,请尝试自己修复它以使用新的jQuery。

The next option is to check if there is an older version of the thing that requires a new jQuery that might work with the older jQuery version. 下一个选项是检查是否有旧版本的东西需要新的jQuery,该版本可能与旧jQuery版本一起使用。

If none of those options work, you can try to use 2 versions of jQuery on your page using jQuery.noConflict() , but this is not recommended. 如果这些选项都不起作用,则可以尝试使用jQuery.noConflict()在页面上使用jQuery的2个版本,但是不建议这样做。 After you load the first version and before you load the second, do something like: 加载第一个版本之后,然后加载第二个版本,请执行以下操作:

j = jQuery.noConflict();

Then use j instead of $ whenever you want to use that version of jQuery, and $ for the second version. 然后使用j而不是$每当你想使用该版本的jQuery和$的第二个版本。

enter code here  <script src="https://code.jquery.com/jquery-3.6.1.js" integrity="sha256-3zlB5s2uwoUzrXK3BT7AX3FyvojsraNFxCc2vC/7pNI=" crossorigin="anonymous"></script>
<script>
    $j = jQuery.noConflict(true);
</script>
<script type="text/javascript" src="vendor/jquery/jquery.min_multi_select.js"></script>

Works well, then you can use $j.ajax({ })效果很好,那么你可以使用 $j.ajax({ })

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

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