Home >Web Front-end >JS Tutorial >Relatively simple code for asynchronously loading JS files_javascript skills

Relatively simple code for asynchronously loading JS files_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:49:511255browse
Copy code The code is as follows:

<script> <br>function getJsFile(url, callBack){ <br>var <br>if(XH.readyState == 4 && XH.status == 200){ <br>if(window.execScript) window.execScript(XH.responseText); <br>else eval.call(window, XH. responseText); <br>eval(callBack)(); <br>} <br>} <br>XH.send(''); <br>} <br></script>



//test
<script> <br>function cb(){ <br>alert(1); <br>abc(); //This is in js9.js <br>} <br>getJsFile('http://www.jb51.net /images/test.js,'cb'); <br></script>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn