// 文件已完成載入,我們可以存取 DOM 元素。
// 子資源(例如腳本、圖片、樣式表和框架)仍在載入中。
const span = document.createElement("span");
span.textContent = "一個
元素。";
document.body.appendChild(span);
break;
case "complete":
// 頁面已完全載入。
console.log(
`第一條 CSS 規則是:${document.styleSheets[0].cssRules[0].cssText}`,
break;
// DOMContentLoaded 事件的替代方案
document.onreadystatechange = () => {
if (document.readyState === "interactive") {
initApplication();
// load 事件的替代方案
document.onreadystatechange = () => {
if (document.readyState === "complete") {
initApplication();
document.addEventListener("readystatechange", (event) => {
if (event.target.readyState === "interactive") {
initLoader();
} else if (event.target.readyState === "complete") {
initApp();
Specification