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     },
  • 相关阅读:
    [置顶] MapReduce 编程之 倒排索引
    java学习之路---线程(重点)
    CentOS下用Tomcat+Zookeeper+Nginx+Solr完美搭建SolrCloud平台(五)
    qsort的几种用法
    两道水题(月之数)(排序)
    快排
    Red and Black(简单dfs)
    zb的生日(暴搜dfs)
    又见01背包
    五子棋
  • 原文地址:https://www.cnblogs.com/friends-wf/p/4668548.html
Copyright © 2011-2022 走看看