The parameters are js address, js internal method name, write a common function for asynchronous loading

1.js file name: tools.js content: function test() { console.log("hello world"); } 2.html <script> function loadScript(url,callback) { var script = document.createElement("script "); script.type="text/javascript"; // IE browser if (script.readyState) { script.onreadystatechange = function() { if (script.readyState == "complete" || script.readyState == "onload") { callback(); } } // safari chrome firefox } else { script.onload = function() { callback(); } } script.src = url; // To better monitor the value of readystate, Call the function first, then load the js, the security is higher document.head.appendChild(script); }

	loadScript("tools.js",function () {
		test();//函数引用
	});
</script>

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325063110&siteId=291194637