zoukankan      html  css  js  c++  java
  • js-script-onreadystatechange事件

    IE的 script 元素支持onreadystatechange事件,不支持onload事件。

    FF的script 元素不支持onreadystatechange事件,只支持onload事件。

    如果要在一个< script src="xx.js"> 加载完成执行一个操作,FF使用onload事件就行了,IE下则要结合onreadystatechange事件和this.readyState,以 下是IE的一个例子:

    <script type="text/javascript" src="xx.js" onreadstatechange="if(this.readyState=='load') alert('loaded');">< /script>
    //this.readyState的值为'loaded'或者'complete'都可以表示这个script已经加载完成.
    
    • 参考一下jquery的源码:
    var script = document_createElement_x('script');
    script.src = "xx.js";
    script.onload = script.onreadystatechange = function() {
    	//ff下没有readyState值,IE存在
        if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete'
        ) {
            alert('loaded');
        }
    };
    
  • 相关阅读:
    第几天?
    农历02__资料
    农历01
    VC6_预编译头
    QWebEngine_C++_交互
    Qt570_CentOS64x64_02
    Qt570_CentOS64x64_01
    QWebEngineView_CssVariables
    Windows__书
    Win7SDK
  • 原文地址:https://www.cnblogs.com/ajaemp/p/13820264.html
Copyright © 2011-2022 走看看