在支持事件 DOMContentLoaded
和属性 document.readyState
的浏览器中:
When
DOMContentLoaded
fires, can I assume that the value ofdocument.readyState
will always be either"complete"
or"interactive"
/"loaded"
?(Or could it be that
document.readyState
sometimes still has the value"loading"
?)
在您的回答中,请提供对权威来源的引用。
您可能想知道:为什么不只听 readystatechange
呢?这是因为Android 2.3.5标准浏览器是目标平台,没有实现readystatechange
事件。
最佳答案
当 DOMContentLoaded
触发时,readyState
属性的值始终是 "interactive"
。 MDN documentation 证明了这一点。声明:
// alternative to DOMContentLoaded event
document.onreadystatechange = function () {
if (document.readyState == "interactive") {
initApplication();
}
}
可与 DOMContentLoaded
处理程序互换。您还可以查看规范 here , 这重申了这一点。
关于javascript - DOMContentLoaded 上的 document.readyState?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13346746/