js异步加载和按需加载
function loadScript(url,callback){
var script = document.creatElement("script");
script.type="text/javascript";
if(script.readyState){
script.onreadystateChange = function(){
if(script.readyState == "complete" || script.readyState=='loaded'){
callback();
}
}
}else{
script.onload=function(){
callback();
}
}
script.src = url;
document.head.appendChild(script);
}
loadScript('test.js',test);