封装一个方法,动态的加载js文件
<span style="font-size:18px;">function loadScript(url,callback){
var script = document.createElement('script');
script.type = 'text/javascript';
if(script.readyState){
// IE
script.onreadystatechange = function(){
if(script.readyState == 'loaded' || script.readyState == 'complete'){
script.onreadystatechange = null;
callback();
}
};
}else{
// Others
script.onload = function(){
callback();
}
}
script.src = url;
document.getElementByTagName('head')[0].appendChild(script);
}</span>