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');
        }
    };
    
  • 相关阅读:
    bzoj 4660
    bzoj 4668
    二项式反演学习笔记
    bzoj 3622
    bzoj 5306
    bzoj 3625
    任意模数NTT(二)
    bzoj 4913
    bzoj 3456
    多项式问题之五——多项式exp
  • 原文地址:https://www.cnblogs.com/ajaemp/p/13820264.html
Copyright © 2011-2022 走看看