窗口负载和窗口准备好之间的区别

时间:2013-12-06 07:12:52

标签: javascript jquery

之间有什么区别
 $(window).load(function () {});

 $(window).ready(function () {});

窗口加载和窗口就绪之间有什么区别?

2 个答案:

答案 0 :(得分:0)

window.ready在已加载所有DOM但是图片可能尚未加载时发生

所有图像加载后都会出现

窗口加载

准备事件首先发生,因此大多数代码都可以放置她

window.onload vs $(document).ready()

答案 1 :(得分:0)

  • document.ready是一个jQuery事件,它在DOM准备就绪时运行

  • window.onload稍后会在加载图片等时触发

示例脚本

$(document).ready(function() {
 // executes when HTML-Document is loaded and DOM is ready
 alert("document is ready");
});


$(window).load(function() {
 // executes when complete page is fully loaded, including all frames, objects and images
 alert("window is loaded");
});

参见

Difference between window load and window ready

window.onload vs. body.onload vs. document.onready