zoukankan      html  css  js  c++  java
  • jquery ready 延迟

    $.holdReady(true);//延迟

    $.holdReady(false);//解延迟

    用于下载文件的时候,异步操作

    $.holdReady(true);

    $.getScript("a.js",function(){

    $.holdReady(false);

    })

    $.holdReady(true);

    $.getScript("b.js",function(){

    $.holdReady(false);

    })

    ......

     内部酷似锁的机制 锁了2次,都加载了之后解锁2次,才继续往下...

     源码:

     1 // Hold (or release) the ready event
     2     holdReady: function( hold ) {
     3         if ( hold ) {
     4             jQuery.readyWait++;
     5         } else {
     6             jQuery.ready( true );
     7         }
     8     },
     9 
    10     // Handle when the DOM is ready
    11     ready: function( wait ) {
    12 
    13         // Abort if there are pending holds or we're already ready
    14         if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {
    15             return;
    16         }
    17 
    18         // Remember that the DOM is ready
    19         jQuery.isReady = true;
    20 
    21         // If a normal DOM Ready event fired, decrement, and wait if need be
    22         if ( wait !== true && --jQuery.readyWait > 0 ) {
    23             return;
    24         }
    25 
    26         // If there are functions bound, to execute
    27         readyList.resolveWith( document, [ jQuery ] );
    28 
    29         // Trigger any bound ready events
    30         if ( jQuery.fn.trigger ) {
    31             jQuery( document ).trigger("ready").off("ready");
    32         }
    33     },
  • 相关阅读:
    ASP.NET刷新页面的六种方法
    web安全攻防实践能力培养引导
    流程控制 ifwhilefor 语句
    迭代器和生成器
    闭包函数装饰器
    元组字典集合及内置方法
    字符编码与文件操作
    字符类型及内置方法
    初识函数
    递归匿名函数常用的内置方法
  • 原文地址:https://www.cnblogs.com/friends-wf/p/4668548.html
Copyright © 2011-2022 走看看