document.readyState

2018-03-08 09:53:39
(.readyState === ) {
   .();
}
{
   .(, .);
}

概述


一个document 的 Document.readyState 属性描述了文档的加载状态。

一个文档的 readyState 可以是以下之一:

  • loading / 加载

  • document 仍在加载。

  • interactive / 互动

  • 文档已经完成加载,文档已被解析,但是诸如图像,样式表和框架之类的子资源仍在加载。

  • complete / 完成

  • T文档和所有子资源已完成加载。状态表示 load 事件即将被触发。

当这个属性的值变化时,document 对象上的readystatechange 事件将被触发。

 

语法

let string = document.readyState;// "complete"

例子

不同的准备状态

switch (document.readyState) {
  case "loading":
    // The document is still loading.
    break;
  case "interactive":
    // The document has finished loading.
    // We can now access the DOM elements.
    var span = document.createElement("span");
    span.textContent = "A <span> element.";
    document.body.appendChild(span);
    break;
  case "complete":
    // The page is fully loaded.
    let CSS_rule = document.styleSheets[0].cssRules[0].cssText;
    console.log(`The first CSS rule is: ${CSS_rule }`);
    break;}
// 模拟 DOMContentLoaded/ jquery readydocument.onreadystatechange = function () {
  if (document.readyState === "interactive") {
    initApplication();
  }}
// 模拟 load/onload 事件document.onreadystatechange = function () {
  if (document.readyState === "complete") {
    initApplication();
  }}

相关链接

规范

  • 2019-07-11 11:35:20

    VirtualBox添加新硬盘

    昨晚在自己的virtualbox中的linux装matlab2010a,没想到硬盘空间不足,所以找了下怎么添加硬盘的资料。也很简单,每几条命令。 大致流程:我的virtualbox版本是3.2.8,linux版本是xubuntu10.01吧貌似

  • 2019-07-23 14:49:40

    Windows10上使用Linux子系统(WSL)

    Linux的Windows子系统让开发人员可以直接在Windows上运行Linux环境(包括大多数命令行工具,实用程序和应用程序),而无需建立在虚拟机的开销之上,整个系统共200多M,但包含了你能用到的所有功能,并且和windows完美互操作(省去linux挂载本地windows分区或目录的操作),目前Linux的windows子系统已经相当完善,可当作完整linux系统使用