当前位置: 代码迷 >> JavaScript >> <转>动态加载js的步骤
  详细解决方案

<转>动态加载js的步骤

热度:140   发布时间:2012-08-27 21:21:57.0
<转>动态加载js的方法
    //加载新的js  
    function _GetJsData(url, callback) {  
        var scripts = document.createElement("script");  
        document.body.appendChild(scripts);  
      
        scripts.onload = function() {  
            callback();  
            document.body.removeChild(this);  
        };  
        scripts.onreadystatechange = function() {  
            if (this.readyState == "loaded") {  
                callback();  
                document.body.removeChild(this);  
            }  
        };  
        scripts.charset = "GBK";  
        scripts.src = url;  
    }  
    _GetJsData('http://www.uefirst.com/index.js',isok);  
    var isok=function(){alert('isok')};  
  相关解决方案