jQuery版本不同及多次引用问题

jQuery版本在不断更新,许多插件并不能很好地工作在各个版本上,并且发现如果在一个页面中多次引用jQuery将会出现问题,害得我折腾了好久,才发现是重复引用问题.

为了避免重复引用,最好在jQuery中处理一下(有些版本已处理),就是在整个文件中用

if(typeof window.jQuery == "undefined") {

.....

}

括起来,可以避免多次引用可能的问题.

这是在jQuery1.3.1a版本中看到的一个方法.

// prevent execution of jQuery if included more than once
if(typeof window.jQuery == "undefined") {
/*
* jQuery 1.1.3a - New Wave Javascript
*
* Copyright (c) 2007 John Resig (jquery.com)
* Dual licensed under the MIT (MIT-LICENSE.txt)
* and GPL (GPL-LICENSE.txt) licenses.
*
* $Date: 2009/06/08 07:59:26 $
* $Rev: 1961 $
*/

// Global undefined variable
window.undefined = window.undefined;

……

在另一个版本中,发现也有类似的处理,但官方下载的最新版1.3.2中没有处理.

(function(){

if(typeof jQuery!="undefined")

var _jQuery=jQuery;

var jQuery=window.jQuery=function(selector,context)

{return this instanceof jQuery?this.init(selector,context):new jQuery(selector,context);};

if(typeof $!="undefined")

var _$=$;

window.$=jQuery;

 

.......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值