Posted in Javascript onJuly 18, 2009
<script> function getJsFile(url, callBack){ var XH = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject('Msxml2.XMLHTTP'); XH.open('get',url,true); XH.onreadystatechange = function(){ if(XH.readyState == 4 && XH.status == 200){ if(window.execScript) window.execScript(XH.responseText); else eval.call(window, XH.responseText); eval(callBack)(); } } XH.send(''); } </script>
//test <script> function cb(){ alert(1); abc(); //这个是在js9.js 中的 } getJsFile('https://3water.com/images/test.js,'cb'); </script>
比较简单的异步加载JS文件的代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@