2012-02-17 14 views
0

Jqueryには、ページが完全に読み込まれたときに$(document).ready()の後に発生する$(window).load()があります。私が理解しているところから$(document).ready()は、ページが完全に読み込まれる前でも起こります。 プレーンなjavascriptには$(window).load()Jqueryに対応するwindow.onloadがあります。 $(document).ready()に対応するjavascriptイベントは何ですか?before window.onload event

+1

[$(document).ready equivalent with jQuery](http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery) –

+0

http://stackoverflow.com/を参照してください。質問/ 1283445/is-there-a-native-javascript-jquerys-document-readyの実装 – Crinsane

+0

http://stackoverflow.com/questions/1206937/javascript-domready – naveen

答えて

0

を答えはここにある:

bindReady: function() { 
    if (readyList) { 
     return; 
    } 

    readyList = jQuery.Callbacks("once memory"); 

    // Catch cases where $(document).ready() is called after the 
    // browser event has already occurred. 
    if (document.readyState === "complete") { 
     // Handle it asynchronously to allow scripts the opportunity to delay ready 
     return setTimeout(jQuery.ready, 1); 
    } 

    // Mozilla, Opera and webkit nightlies currently support this event 
    if (document.addEventListener) { 
     // Use the handy event callback 
     document.addEventListener("DOMContentLoaded", DOMContentLoaded, false); 

     // A fallback to window.onload, that will always work 
     window.addEventListener("load", jQuery.ready, false); 

    // If IE event model is used 
    } else if (document.attachEvent) { 
     // ensure firing before onload, 
     // maybe late but safe also for iframes 
     document.attachEvent("onreadystatechange", DOMContentLoaded); 

     // A fallback to window.onload, that will always work 
     window.attachEvent("onload", jQuery.ready); 

     // If IE and not a frame 
     // continually check to see if the document is ready 
     var toplevel = false; 

     try { 
      toplevel = window.frameElement == null; 
     } catch(e) {} 

     if (document.documentElement.doScroll && toplevel) { 
      doScrollCheck(); 
     } 
    } 
}, 

これは(window.onloadに対応

1
$(document).ready() 

jQueryのsource codeから)、.ready() HTML DOMがブラウザウィンドウにロードされた後に実行します。

jQueryの.load()は、すでに開いているウィンドウのコンテキストにランダムなURLをロードするために使用できます。ajax呼び出しのように。