如何避免两个版本的Jquery库之间的冲突? [英] How to avoid conflict between two version of Jquery library?

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

问题描述

在jsp页面中,我使用的是struts2-jquery-plugin-3.2.1.jar(内部使用jquery-1.6.4.js),我使用的是facebox(它使用jquery-1.4.3.min.js) ).所以我的struts2-jquery-plugin-3.2.1.jar首先加载,然后是facebox jquery.但是当我放置jquery-1.4.3.min.js时,我的struts2-jquery-plugin-3.2.1.jar停止工作,而当我删除jquery-1.4.3.min.js时,我的facebox显然停止了工作.我关注以下论坛:此处此处,但无法解决此问题.家伙建议我使用新版本的struts2-jquery-plugin,但是我不能使用,因为如果我使用新版本的struts2-jquery-plugin,那么我项目的某些代码将停止工作.请分享您对这个问题的知识.

In jsp page, i am using struts2-jquery-plugin-3.2.1.jar (it uses internally jquery-1.6.4.js) and i am using facebox (it uses jquery-1.4.3.min.js). So my struts2-jquery-plugin-3.2.1.jar load first then facebox jquery. but when i put jquery-1.4.3.min.js my struts2-jquery-plugin-3.2.1.jar stops working and when i remove jquery-1.4.3.min.js obviously my facebox stops working. I follow these forum : here and here but not able to fix this problem.One guy advise me to use new version of struts2-jquery-plugin, but i can't use because if i use new version of struts2-jquery-plugin then some code of my project stopped working. Please share your knowledge on this problem.

推荐答案

,您需要使用jQueryNoConflict功能: http://api.jquery.com/jQuery.noConflict/

you need to use jQueryNoConflict feature: http://api.jquery.com/jQuery.noConflict/

因此您的库需要定义为:

so your library needs to be defined like:

<script src='jquery-1.3.2.js'></script>
<script>
var jq132 = jQuery.noConflict();
</script>

<script src='jquery-1.4.2.js'></script>
<script>
var jq142 = jQuery.noConflict();
</script>

然后可以像这样同时使用它们:

and then you can use both of them like this:

jq132.ajax(....);
jq142('#my-elem').hide();

这篇关于如何避免两个版本的Jquery库之间的冲突?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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