zoukankan      html  css  js  c++  java
  • 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;

     

    .......

  • 相关阅读:
    jQuery检测滚动条(scroll)是否到达底部
    sql group by
    hbm.xml 详解总结
    net.sf.json 时间格式的转化
    经典SQL语句大全
    HashTable
    in与exist , not in与not exist 的区别
    网页布局常用的一些命名规则和书写
    什么是SOA?
    sql之left join、right join、inner join的区别
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/1505133.html
Copyright © 2011-2022 走看看