2012-02-17 2 views
0

В JQuery есть $ (window) .load(), которое происходит после $ (document) .ready(), когда страница полностью загружена. Из того, что я понимаю $ (document) .ready(), происходит даже до полной загрузки страницы. В простом javascript есть окно window.onload, которое соответствует $ (window) .load() JQuery. Какое javascript событие соответствует $ (document) .ready()?До события window.onload

+1

Возможный дубликат [$ (document) .ready эквивалент без jQuery] (http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery) –

+0

См. Http://stackoverflow.com/ вопросы/1283445/is-there-a-native-javascript-реализация-of-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(); 
     } 
    } 
}, 

из JQuery source code

1
$(document).ready() 

это соответствует window.onload(), .ready() выполняется после загрузки HTML-DOM в окне браузера

.load() в jQuery можно использовать для загрузки случайного URL-адреса в контекст уже открытого окна .. как вызов ajax.

Смежные вопросы