Jquery-core.holdReady()
jQuery.holdReady()
Description: Holds or releases the execution of jQuery's readyevent.
描述:鎖定或者釋放jQuery的完成事件。
version added:1.6jQuery.holdReady( hold )
于1.6版本的jQuery加入該函數(shù)
?
jQuery.holdReady(hold) whether the ready hold is being requestedor released
The $.holdReady() method allows the caller to delay jQuery'sready event. This advanced feature would typically be used by dynamic scriptloaders that want to load additional JavaScript such as jQuery plugins beforeallowing the ready event to occur, even though the DOM may be ready. Thismethod must be called early in the document, such as in the <head>immediately after the jQuery script tag. Calling this method after the readyevent has already fired will have no effect.
To delay the ready event, first call $.holdReady(true). When theready event should be released to execute, call $.holdReady(false). Note thatmultiple holds can be put on the ready event, one for each $.holdReady(true)call. The ready event will not actually fire until all holds have been releasedwith a corresponding number of $.holdReady(false) calls and the normal documentready conditions are met. (Seeready for more information.)
?
jQuery.holdReady(hold) hold表示完成事件的狀態(tài)(被鎖定或釋放) $.holdReady()方法允許jQuery的完成事件被該函數(shù)鎖定。這個高級特性的典型應(yīng)用場合是動態(tài)載入腳本,比如jQuery插件等。在附加的腳本載入完成前,即使頁面已經(jīng)準(zhǔn)備好,jQuery的完成事件也不會被觸發(fā)。這個函數(shù)必須在頁面的靠前部分被調(diào)用,比如在<head>標(biāo)簽當(dāng)中,jQuery載入下一行。在完成事件被觸發(fā)后調(diào)用此函數(shù)沒有任何效果。使用方法:首先調(diào)用$.holdReady(true)[調(diào)用后完成事件將被鎖定]。當(dāng)準(zhǔn)備好觸發(fā)完成事件時,調(diào)用$.holdReady(false)。需要注意的是,可以對完成事件添加多個鎖定,每個鎖定對應(yīng)一次$.holdReady(false)[解鎖]調(diào)用。jQuery的完成事件將在所有的鎖定都被解除,并且頁面也已經(jīng)準(zhǔn)備好的情況下被觸發(fā)。
Example:
Delay the ready event until acustom plugin has loaded.
例子:鎖定完成事件直到用戶腳本[myplugin.js]載入完成
$.holdReady(true); $.getScript("myplugin.js", function() { ???? $.holdReady(false); });
以上是現(xiàn)成度娘來的資料,以下詳細解釋一些其他的試驗代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"><title></title><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js" ></script><script type="text/javascript">$(function () { alert($("#div_test").html()); })</script> </head> <body><form id="form1" runat="server"><div id="div_test">this is a test!</div></form> </body> </html>?
該代碼的運行結(jié)果是 跳出this is a test! 正常運行,現(xiàn)在講代碼改如下:
<script type="text/javascript">$.holdReady(true);$(function () { alert($("#div_test").html()); })</script>代碼將不會跳出彈出窗口。因為$.holdReady(true);鎖定了Jquery對象。再后面加上$.holdReady(false);釋放代碼就恢復(fù)正常。
?
<script type="text/javascript">$.holdReady(true);$(function () { alert($("#div_test").html()); })$.holdReady(false);</script>?
?
?
?
?
?
轉(zhuǎn)載于:https://www.cnblogs.com/wujiang/archive/2012/05/16/2503538.html
總結(jié)
以上是生活随笔為你收集整理的Jquery-core.holdReady()的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 一位程序员的忠告
- 下一篇: pe文件被装入内存时按64k对齐