jquery的ready()实现的是 domcontentloaded 事件,domcontentloaded与window load事件的区别
简单的说ready()是在文档加载完成就会触发,此时图片等资源可能还没有完全加载, load是在所有资源都加载完成后才会触发
看下ready函数的代码就什么都清楚了。下面的代码加上了注释:
// 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 ); } } },
以上所述就是本文的全部内容了,希望大家能够喜欢。
