简体   繁体   English

如何解决两个jquery冲突?

[英]How to resolve two jquery conflict?

I have a page which includes jquery for curtain effects and other for slider.the problem i am facing is my both jqueries are not working together.what should i do?我有一个页面,其中包含用于窗帘效果的 jquery 和其他用于滑块的页面。我面临的问题是我的两个 jquery 无法协同工作。我该怎么办?

my sample code is我的示例代码是

    <!-- for slider -->
<script src="images/jquery-latest.js" type="text/javascript"></script>
<script src="images/jquery.bxslider2.min.js" type="text/javascript"></script>
<script src="images/scripts.js" type="text/javascript"></script>

    <!-- for curtain -->
<script type="text/javascript" src="js/jquery-1.3.2.js"></script>
<script src="js/jquery.easing.1.3.js" type="text/javascript"></script>  

First of all, try using the current jQuery version (1.7.2) and see if both scripts work.首先,尝试使用当前的 jQuery 版本 (1.7.2)并查看两个脚本是否都有效。

If not, consider using something that is compatible with the current jQuery version - if something requires jquery 1.3 it wasn't updated for a long time.如果没有,请考虑使用与当前 jQuery 版本兼容的东西 - 如果某些东西需要 jquery 1.3,它很长时间没有更新。

If you really need both scripts and both requires different jQuery versions, then you'll need to do it like this:如果你真的需要这两个脚本并且都需要不同的 jQuery 版本,那么你需要这样做:

<script src=".../jquery-1.3.2.js"></script>
<script src="script-that-needs-132.js"></script>
<script>var jQuery132 = $.noConflict(true);</script>
<script src=".../jquery-1.7.2.js"></script>

To use the old jQuery, then wrap the code, using it, like this:要使用旧的 jQuery,请包装代码,使用它,如下所示:

(function($){
    // here $ points to the old jQuery
})(jQuery132);

删除其中之一,最好是这个<script type="text/javascript" src="js/jquery-1.3.2.js"></script>

You can use您可以使用

 <script type="text/javascript" language="javascript">
    var jq = jQuery.noConflict();
</script>

You can't/shouldn't include two different versions of jQuery.您不能/不应该包含两个不同版本的 jQuery。 Stick to one (the most recent one should be the best choice).坚持一个(最近的一个应该是最好的选择)。 If your desired plugin does only support a very ancient version like 1.3 is, then you should choose a more recent one or start fiddling around in the code.如果你想要的插件只支持像 1.3 这样的非常古老的版本,那么你应该选择一个更新的版本或者开始在代码中摆弄。

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

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