$.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 ready11 ready: function( wait ) {12 13 // Abort if there are pending holds or we're already ready14 if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) {15 return;16 }17 18 // Remember that the DOM is ready19 jQuery.isReady = true;20 21 // If a normal DOM Ready event fired, decrement, and wait if need be22 if ( wait !== true && --jQuery.readyWait > 0 ) {23 return;24 }25 26 // If there are functions bound, to execute27 readyList.resolveWith( document, [ jQuery ] );28 29 // Trigger any bound ready events30 if ( jQuery.fn.trigger ) {31 jQuery( document ).trigger("ready").off("ready");32 }33 },