`function loadScript() { var script = document.createElement('script'), head = document.getElementsByTagName('head')\[0\]; script.type = 'text/javascript'; script.charset = 'UTF-8'; script.src = urls\[num\]; if (script.addEventListener) { script.addEventListener('load', function () { num = num+1; if(num < urls.length) { loadScript(); }else if(num == urls.length){ jQuery(document).ready(function($) { $('#multiselect').multiselect(); }); } }, false); } else if (script.attachEvent) { script.attachEvent('onreadystatechange', function () { var target = window.event.srcElement; if (target.readyState == 'loaded') { num = num+1; if(num < urls.length) { loadScript(); } }else if(num == urls.length){ jQuery(document).ready(function($) { $('#multiselect').multiselect(); }); } }); } head.appendChild(script); } function loadJsWithCommon(){ loadScript(); } function loadCommon(jsPath){ urls.push(jsPath); loadScript(); waitLoad(); waitLoadsetInterval(); sessionStorage.setItem("loaded",""); console.log("最后执行"); document.addEventListener("DOMContentLoaded", function(event) { console.log("DOM fully loaded and parsed"); console.log("1是否有加载了loaded判断"+sessionStorage.getItem("loaded")); }); }javascript
var waitLoad = function(){ if(num < urls.length){ setTimeout("waitLoad()", 300) } }java
function waitLoadsetInterval(){ var timer= window.setInterval(function () { console.log("waitLoadsetInterval 判断"); if(num >= urls.length){ console.log("js加载完成"); window.clearInterval(timer); angular.element(document).ready(function() { console.log("2是否有加载了loaded判断"+sessionStorage.getItem("loaded")); if(!sessionStorage.getItem("loaded")){ console.log("获取的ng-app名称"+document.getElementsByTagName("body")\[0\].attributes\["ng-app"\].value); angular.bootstrap(document.getElementsByTagName("body")\[0\], \[document.getElementsByTagName("body")\[0\].attributes\["ng-app"\].value\]); } }); } }, 1000); }`bootstrap
问题是<body ng-app="" 在js异步加载没完成就启动了 因此找不到模块 因此咱们监听js加载完再去判断一次 有执行过咱们就不用执行 没脚本在启动一次 ------相似天龙八部里面的珍珑棋局逻辑……session