When is event DOMContentLoaded triggered?
DOMContentLoaded 何时触发?
Once the user agent stops parsing the document, the user agent must run the following steps:
当客户端停止解析文档后, 必须执行以下几步:
1. Set the current document readiness to “interactive” and the insertion point to undefined.设置当前文档的状态为“inactive” 并设置插入点为 undefined。
Pop all the nodes off the stack of open elements.
2. If the list of scripts that will execute when the document has finished parsing is not empty, run these substeps:
2.1 Spin the event loop until the first script in the list of scripts that will execute when the document has finished parsing has its “ready to be parser-executed” flag set and the parser’s Document has no style sheet that is blocking scripts.
2.2 Execute the first script in the list of scripts that will execute when the document has finished parsing.
2.3 Remove the first script element from the list of scripts that will execute when the document has finished parsing (i.e. shift out the first entry in the list).
2.4 If the list of scripts that will execute when the document has finished parsing is still not empty, repeat these substeps again from substep 1.3. Queue a task to fire a simple event that bubbles named DOMContentLoaded at the Document.

本文详细解释了DOMContentLoaded事件触发的时机及过程。当浏览器完成解析文档但未加载完所有资源时触发此事件。文章还介绍了在此事件触发前浏览器如何处理待执行的脚本。
68

被折叠的 条评论
为什么被折叠?



