如何在JS文件上使用不同版本的JQuery? [英] How to use different version of JQuery on a JS file?

查看:85
本文介绍了如何在JS文件上使用不同版本的JQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于使用JQuery 1.4.2的Cisco JS库,我正在开发的UI页面上使用最新的2.X版JQuery。



思科图书馆



我使用上述库链接中的Jabberwerx.js文件。



库工作正常,如果加载的JQuery是1.4,但无法与更高版本的JQuery一起使用。如果我使用旧版本的Jquery,那么基于bootstrap的我的UI不起作用。我试图使用noConflict(),但是我无法编辑整个非常庞大的库。在库上有很多webservice调用和函数,所以升级它非常麻烦。

是否可以在此JS文件上使用特定版本的JQuery,而其余应用程序可以使用最新版本的JQuery?



库上有这个代码。我们可以改变这一点,使它使用旧版本的JQ。

$ $ $ $ $ $ $ $ $ $ b $ $ b $ $ {$ c $($) $ b返回新的jQuery.fn.init(选择器,上下文);
},
_jQuery = window.jQuery,
_ $ = window。$,
}

我没有在同一页面上使用不同版本的JQuery,但我试图限制使用JQuery的一个版本添加到其中一个JS文件中。

解决方案

当您使用不同版本的jquery时,您的代码会发生冲突。可能会出现明显的错误。



要修复它,您需要使用 $。noConflict()传递布尔参数 true

  jQuery.noConflict(true); 
//删除jquery本身并允许您使用不同版本的jquery

示例:

 < script src =jquery-version-1.0 >< /脚本> 
< script> //代码为v-1< / script>
< script> jQuery.noConflict(true); //删除jquery< / script>
< script src =jquery-version-2.0>< / script><! - 使用其他版本 - >
< script> // code for v-2< / script>


I have a Cisco JS library designed to work using JQuery 1.4.2 and I'm using latest 2.X version of JQuery on the UI page I'm developing.

Cisco Library

I'm using Jabberwerx.js file from the above library link.

The library works fine if the JQuery loaded is of 1.4 but fails to work with later versions of JQuery. If I use old version of Jquery my UI based on bootstrap doesn't work. I tried to use noConflict() but then I can not edit the entire library which is very huge. There are lots of webservice calls and functions on the library so upgrading it is very painstaking.

Is it possible to use a particular version of JQuery on this JS file and the rest of the application can use the latest version of JQuery?

The library has this code on it. Can we change this to make it work using old version of JQ.

(function(window)
{   var jQuery=function(selector,context)
    {
        return new jQuery.fn.init(selector,context);
    },
    _jQuery=window.jQuery,
    _$=window.$,
}

I'm not looking at using different versions of JQuery on the same page but I'm trying to limit the usage of one version of JQuery to one of the JS files.

解决方案

When you use different version of jquery then your code conflicts. So there may appear obvious errors.

To fix it, you need to use $.noConflict() passing a boolean parameter true.

jQuery.noConflict(true);
//removes jquery itself and allows you to work with different version of jquery

Example:

<script src="jquery-version-1.0"></script>
<script>//code for v-1</script>
<script>jQuery.noConflict(true);//remove jquery</script>
<script src="jquery-version-2.0"></script><!--use another version-->
<script>//code for v-2</script>

这篇关于如何在JS文件上使用不同版本的JQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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