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;

     

    .......

  • 相关阅读:
    Postman+Newman+jenkins实现API自动化测试
    抓包,反抓包,反反抓包
    使用Magisk+riru实现全局改机
    stat命令的实现-mysate(必做)
    第五章学习笔记
    第四章学习笔记
    2.3.1测试
    缓冲区溢出
    学习笔记6
    电子公文传输系统团队项目——需求规格说明书
  • 原文地址:https://www.cnblogs.com/GarfieldTom/p/1505133.html
Copyright © 2011-2022 走看看