UI5 framework异步加载javascript的solution - 动态创建script node

Created by Jerry Wang, last modified on Sep 22, 2015

includeScript

createElement

<html>

<script>

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();

           } // end of readyState

       }; // end of onreadystatechange

   } // end of IE

   else { //Others

       script.onload = function(){

        callback();

    };

}

script.src = url;

document.getElementsByTagName("head")[0].appendChild(script);

}

loadScript("026_test.js", function(){

console.log("File is loaded!");

hello();

});

</script>

</html>


UI5 framework异步加载javascript的solution - 动态创建script node

UI5 框架的use case:

UI5 framework异步加载javascript的solution - 动态创建script node



上一篇:《自己动手写Docker》书摘之四: 构造简单容器


下一篇:使用Delve进行Golang代码的调试