這篇文章主要介紹了html' target='_blank'>jquery中ready()函數(shù)執(zhí)行的時(shí)機(jī)和window的load事件比較的相關(guān)資料,需要的朋友可以參考下
jquery的ready()實(shí)現(xiàn)的是 DOMContentLoaded 事件,DOMContentLoaded與window load事件的區(qū)別
簡(jiǎn)單的說(shuō)ready()是在文檔加載完成就會(huì)觸發(fā),此時(shí)圖片等資源可能還沒(méi)有完全加載, load是在所有資源都加載完成后才會(huì)觸發(fā)
看下ready函數(shù)的代碼就什么都清楚了。下面的代碼加上了注釋:
?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 // Handle when the DOM is ready ready: function() { // Make sure that the DOM is not already loaded if ( !jQuery.isReady ) { // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). if ( !document.body ) { return setTimeout( jQuery.ready, 13 ); } // Remember that the DOM is ready jQuery.isReady = true; // If there are functions bound, to execute if ( readyList ) { // Execute all of them var fn, i = 0; while ( (fn = readyList[ i++ ]) ) { fn.call( document, jQuery ); } // Reset the list of functions readyList = null; } // Trigger any bound ready events if ( jQuery.fn.triggerHandler ) { jQuery( document ).triggerHandler( "ready" ); } } },以上所述就是本文的全部?jī)?nèi)容了,希望大家能夠喜歡。
鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。
新聞熱點(diǎn)
疑難解答
圖片精選