如何解决两个jquery冲突? [英] How to resolve two jquery conflict?

查看:87
本文介绍了如何解决两个jquery冲突?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面,其中包括用于窗帘效果的jquery和其他用于slide.the我面临的问题是我的两个jqueries不能一起工作。我该怎么办?

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?

我的示例代码是

    <!-- 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>  


推荐答案

首先,尝试使用当前的jQuery版本(1.7.2)并查看两个脚本是否都有效。

First of all, try using the current jQuery version (1.7.2) and see if both scripts work.

如果没有,请考虑使用与当前jQuery版本兼容的东西 - 如果某些东西需要jquery 1.3,它很长时间没有更新。

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版本,你需要这样:

If you really need both scripts and both require different jQuery versions, you'll need to to it like this:

<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>

要使用旧的jQuery,请使用它包装代码:

To use the old jQuery you then wrap the code using it like this:

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

这篇关于如何解决两个jquery冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆