【问题标题】:How is the onreadystatechange event supported everywhere but document.readyState isn't?到处都支持 onreadystatechange 事件,但 document.readyState 不支持?
【发布时间】:2019-06-22 16:13:50
【问题描述】:

根据 MDN herehere,它说所有浏览器都支持 readystatechange 事件,但 document.readyState 属性只支持到 IE9+ (8*) 左右。

考虑到readystatechange 事件的字面定义是:

readystatechange 事件在文档的 readyState 属性发生变化时触发。

除非readystatechange 的先前实现将document.readyState 保留为无法访问的内部变量。是这种情况,还是仅仅是文档错误?

【问题讨论】:

    标签: javascript internet-explorer events cross-browser readystate


    【解决方案1】:

    它看起来像一个文档错误。我尝试在 IE 11 中使用不同的文档模式测试 document.readyState 属性,它适用于所有文档模式,因此类似的应该适用于所有版本的 IE。

    测试代码:

    <!DOCTYPE html>
    <html>
    <body>
    
    <p>Click the button to display the loading status of the current document.</p>
    
    <button onclick="myFunction()">Try it</button>
    
    <p id="demo"></p>
    
    <script>
    function myFunction() {
      var x = document.readyState;
      document.getElementById("demo").innerHTML = x;
    }
    </script>
    
    </body>
    </html>

    输出:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      • 1970-01-01
      • 2018-03-10
      • 2016-10-14
      • 1970-01-01
      • 2019-11-21
      相关资源
      最近更新 更多