Skip to content

Instantly share code, notes, and snippets.

@suncn
Last active August 8, 2017 06:33
Show Gist options
  • Save suncn/ea3defe1f58c6e1565b3b088608d0abc to your computer and use it in GitHub Desktop.
Save suncn/ea3defe1f58c6e1565b3b088608d0abc to your computer and use it in GitHub Desktop.
页面加载完成执行事件load
document.addEventListener("DOMContentLoaded", function() {
// ...代码...
}, false);
window.addEventListener("load", function() {
// ...代码...
}, false);
DOM文档加载的步骤为
解析HTML结构。
加载外部脚本和样式表文件。
解析并执行脚本代码。
DOM树构建完成。//DOMContentLoaded
加载图片等外部文件。
页面加载完毕。//load
在第4步,会触发DOMContentLoaded事件。在第6步,触发load事件。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment