动态加载js脚本函数封装
优点:js代码加载不阻塞浏览器其他的执行
function loadScript(url,fn){
var oScript = document.createElement('script');
script.src=url;
document.getElementsByTagName('head')[0].appendChild(oScript);
if(window.addEventListener){//高版本浏览器
oScript.onload = function(){
fn && fn();
}
}else{//IE低版本浏览器
oScript.onreadystatechange = function(){
if(oScript.readyState='loaded' || oScript.readyState='compltet'){
oScript.onreadychange = null;
fn && fn();
}
}
}
}