测验

你为什么会使用类似 `load` 事件的东西?

此事件有缺点吗? 你知道任何替代方案,以及你为什么会使用这些替代方案?
主题
Web APIJavaScript

load 事件在文档加载过程结束时触发。 此时,文档中的所有对象都在 DOM 中,并且所有图像、脚本、链接和子框架都已完成加载。

DOM 事件 DOMContentLoaded 将在页面 DOM 构建完成后触发,但不会等待其他资源完成加载。 在某些情况下,当您不需要在初始化之前加载整个页面时,这是首选。

练习

检验你的理解
测试版
检验你的理解 练习
检验你的理解 练习

A script only needs the parsed DOM to attach behavior; it does not depend on images or subframes finishing. Which event is the better readiness boundary?