小编pep*_*600的帖子

动态创建脚本:readyState永远不会"完成"

我试图在脚本完全加载后做一些事情.(IE8)

我用于测试的脚本:http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
和无效的脚本:http://ajax.googleapis.com/ajax/libs/的jquery/1.5.1/jquery.minaaaaaaaa.js

代码...

var script = create the element and append to head...

// this works fine with FF/Chrome/...
script.onload = function() {alert('script loading complete');}
script.onerror = function() {alert('error loading script');}

// and for IE
script.onreadystatechange = function() {
    // this will alert 1.loading 2.loaded
    alert(this.readyState);

    // this never works
    if(this.readyState == 'complete') {alert('script loading complete');}

    // this works with either a valid or INVALID url
    else if(this.readyState == 'loaded') {alert('script loaded');}
}; …
Run Code Online (Sandbox Code Playgroud)

javascript readystate onreadystatechange

10
推荐指数
2
解决办法
1万
查看次数