包含两个以上的JQuery库会产生问题 [英] Inclusion of more than two JQuery libraries creates problems

查看:79
本文介绍了包含两个以上的JQuery库会产生问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我包括以下JQuery库:

I am including these JQuery libraries:

src="JQuery/jquery-1.4.2.min.js"
src="JQuery/jquery-ui-1.8.6.custom.min.js
src="JQuery/menu_login.js"
src="GjQuery/jquery-1.2.6.min.js"
src="GjQuery/jquery-ui-personalized-1.6rc2.min.js
src="GjQuery/jquery.flickr-1.0.js"
"GjQuery/jquery.flickrGallery-1.0.2.js"
<script type="text/javascript"> 
$().ready(function(){
$('#Gallery').flickrGallery({
    galleryHeight: 450
});
});
</script>

在这段代码中,我在Web应用程序中包括3个JQuery库.在Web应用程序运行正常之前,我有两个查询,但是当我添加了flickr库时,就出现了问题.问题是当我包含flickr库时,其他两个将停止工作.如果我更改包含的顺序,则flickr库将停止唤醒或从其他两个库中停止工作.任何的想法?

In this code, I am including 3 JQuery libraries in my Web application. I have two queries in my Web application before it's working fine, but when I have added the flickr library, it's doing problem. Problem is that as I include flickr library, the other two stop working. If I change the order of the inclusion then flickr library stops wroking or from other two one not doing work. Any idea?

推荐答案

包括多个版本的jQuery的目的是什么?

What is the purpose behind including multiple versions of jQuery?

如果可以,请仅使用1个版本(希望是最新版本).

If you can, use only 1 (newest hopefully) version.

或者,如果您使用的每个插件都需要不同的版本,请使用NoConflict并确保每个插件都获得了所需的正确版本.您还可以使用闭包和自调用函数来像平常一样使用$,同时控制使用的版本.

Alternatively, if each plugin you are using requires a different version, use NoConflict and make sure each plugin gets the correct version that it needs. You can also use closures and self invoking functions to still use $ like normal, while controlling which version you're using.

<script src="http://code.jquery.com/jquery-1.4.2.js"></script>
<!-- other scripts that depend on 1.4.2 --->
<script>
var $.1.4.2 = $.noConflict(true);
</script>

<script src="http://code.jquery.com/jquery-1.2.6.js"></script>
<!-- other scripts that depend on 1.2.6 --->
<script>
var $.1.2.6 = $.noConflict(true);
</script>

<script>
(function($){  
  // $ in here is jQuery 1.4.2 
})($.1.4.2);

(function($){
  // $ in here is jQuery 1.2.6 
})($.1.2.6);
</script>

这篇关于包含两个以上的JQuery库会产生问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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