Assuming browser that supports the event:
document
. jQuery will only use the document
it was loaded in, no matter what you pass to it.‘DOMContentLoaded‘
event will do nothing if the event has already happened.There is no delay in these browsers, see http://jsfiddle.net/rqTAX/3/ (the offsets logged are in milliseconds).
For browsers that don‘t support the event, jQuery‘s will obviously work for them as well. It will use a hacky mechanism that is not the same as the real DOMContentLoaded
and will not necessarily fire as soon as the real DOMContentLoaded
would:
// The DOM ready check for Internet Explorer
function doScrollCheck() {
if ( jQuery.isReady ) {
return;
}
try {
// If IE is used, use the trick by Diego Perini
// http://javascript.nwbox.com/IEContentLoaded/
document.documentElement.doScroll("left");
} catch(e) {
setTimeout( doScrollCheck, 1 );
return;
}
// and execute any waiting functions
jQuery.ready();
}
jquery ready vs domcontentloaded
原文:http://www.cnblogs.com/aloha/p/5255175.html