//动态添加脚本,当脚本下载完成且准备就绪后执行回调函数。(这也是推荐的无阻塞的方法)
function loadScript(url,callback){
var script=document.creatElement('script');
script.type='text/javascript';
if(script.readyState){ //IE
script.onreadystatechange=function(){
if(script.readyState == 'loaded' || script.readyState == 'complete'){
script.onreadystatechange=null;
callback();
}
}
}else{ //非IE
script.onload=function(){
callback();
}
}
script.src=url;
document.getElementsByTagName('head')[0].appendChild(script);
}
网友评论