问题
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.
回答1:
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();
回答2:
Just use the latest jQuery (in your case 1.6.4.js) and it will work. Don't update to 1.9 though as it contains multiple breaking changes.
There is no reason why the facebox should stop working if you remove the jquery-1.4.3. All deprecated methods from 1.4 are included in 1.6.
Check the console for errors.
来源:https://stackoverflow.com/questions/15498455/how-to-avoid-conflict-between-two-version-of-jquery-library