When is event DOMContentLoaded triggered

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

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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. 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值