During Web development, we may encounter the following situation: we need to reference another j through a js file.
During Web development, you may encounter this situation: we need to reference functions in another js file through one js file, however, is there a way for another function to load data through the script tag on the page. Therefore, we have the need to dynamically load js files through js. The following provides a solution.
The method is relatively simple. For details about the instance, see the code:
File 1: demo. js
function demo(){alert("demo");}
File 2: test. js
function test(){alert("test");} function loadDemo(){var iHead = document.getElementsByTagName('HEAD').item(0); var iScript= document.createElement("script"); iScript.type = "text/javascript"; iScript.src="demo.js"; iHead.appendChild(iScript); }
File 3: test.html
Insert title here