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-04-25 15:40:16

    JS对象是否拥有某属性如何判断

    原型链上继承过来的属性无法通过hasOwnProperty检测到,返回false。 需注意的是,虽然in能检测到原型链的属性,但for in通常却不行。

  • 2019-04-30 11:23:36

    elasticsearch和analysis-ik的安装使用

    全文搜索和中文分词主要介绍了两组全文搜索加中文分词方案; TNTSearch+jieba-php这套组合对于博客这类的小项目基本够用了;

  • 2019-04-30 11:42:24

    php7+laravel+coreseek(sphinx)中文搜索初步实现(Linux)

    官网www.coreseek.cn已不能下载,所以需从网上找资源, 注意的一点是,笔者安装coreseek-3.2.14版本后,使用时提示client版本高于server版本的错误, php的sphinx扩展,为使用者,为client;coreseek是系统服务,为server