在Jquery中,$(window).load()发生在$(document).ready()之后,当页面完全加载时。根据我的理解,$(document).ready()甚至在页面完全加载之前就会发生。 在普通的javascript中有window.onload,它对应于$(window).load()Jquery。 什么javascript事件对应于$(document).ready()?
答案 0 :(得分:1)
$(document).ready()
这对应于window.onload(),. ready()在浏览器窗口中加载HTML DOM后执行
jQuery中的.load()可用于在已经打开的窗口上下文中加载随机URL ..就像ajax调用一样。
答案 1 :(得分:0)
答案 2 :(得分: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 的