function creatrScript(jsUrl,callback) {
var _doc = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', jsUrl);
_doc.appendChild(script);
script.onload = script.onreadystatechange = function() {
if (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') {
callback();
}
script.onload = script.onreadystatechange = null;
}
}
creatrScript("jsUrl",function(){
alert("ok")
});
来源网络,稍作修改
网友评论