Skip to content

Instantly share code, notes, and snippets.

@ziluo
Last active December 15, 2015 05:39
Show Gist options
  • Save ziluo/5210469 to your computer and use it in GitHub Desktop.
Save ziluo/5210469 to your computer and use it in GitHub Desktop.
无阻塞的JS加载模式
<script type="text/javascript">
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{
script.onload = function(){
callback();
};
}
script.src = url;
document.getElementByTagName('head')(0).appendChild(script);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment