前端js呼叫js
阿新 • • 發佈:2019-02-12
//A function show_A () { console.log("show_A"); } //B //程式程式碼 new_element=document.createElement("script"); new_element.setAttribute("type","text/javascript"); new_element.setAttribute("src","js/a.js"); document.body.appendChild(new_element); //window.loading() window.onload=function(){ show_B (); } function show_B () { show_A(); console.log("show_B"); } //index.html-----看列印結果就明白了 <html> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" /> <meta charset="UTF-8"/> <body> </body> <script type="text/javascript" src="js/jquery-1.8.3.js" ></script> <script type="text/javascript" src="js/b.js" ></script> </html>