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>