動態載入JS的方法

悠悠隱於市發表於2011-04-22
//載入新的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')}; 

 

 

http://www.uefirst.com/bbs/read-htm-tid-22.html

相關文章