jquery ready 延迟

$.holdReady(true);//延迟html

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

 

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

$.holdReady(true);spa

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

$.holdReady(false);orm

})htm

$.holdReady(true);blog

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

$.holdReady(false);rem

})

......

 内部酷似锁的机制 锁了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     },

 

转载于:https://www.cnblogs.com/friends-wf/p/4668548.html