首页 > PHP资讯 > HTML5培训技术 > 封装实现JavaScript文件的动态加载功能

封装实现JavaScript文件的动态加载功能

HTML5培训技术
function loadScript(url, callback){var script = document.createElement ("script")script.type = "text/javascript";if (script.readyState){ //IEscript.onreadystatechange = function(){if (script.readyState == "loaded" || script.readyState == "complete"){script.onreadystatechange = null;callback();}};} else { //Othersscript.onload = function(){callback();};}script.src = url;document.getElementsByTagName_r("head")[0].appendChild(script);}
loadScript("file1.js", function(){alert("File is loaded!");});


HTML5培训技术

本文由欣才IT学院整理发布,未经许可,禁止转载。
支持39不支持0