动态引入Js文件
var src = "/Scripts/Test.js"; $("<script type = 'text/javascript' src='" + src + "'><\/script>").appendTo("head"); //动态加载 TestAlert123123(); //调用Test.js中的函数
二、顺序添加(QQ)
<img src="1.jpg" width="200" height="300" /> <script src="jquery/jquery-1.4.1.js" type="text/javascript"></script> <script src="js/hello.js" type="text/javascript"></script> <script src="js/world.js" type="text/javascript"></script> <script type="text/javascript"> function loadScript(url, callback) { var script = document.createElement("script"); script.type = "text/javascript"; //IE if (script.readyState) { script.onreadystatechange = function () { if (script.readyState == "loaded" || script.readyState == "complete") { script.onreadystatechange = null; callback(); } } } else { //非IE script.onload = function () { callback(); } } script.src = url; document.getElementById("head").appendChild(script); } //第一步加载jquery类库 loadScript("jquery/jquery-1.4.1.js", function () { //第二步加载hello.js loadScript("js/hello.js", function () { //第三步加载world.js loadScript("js/world.js", function () { }); }); }); </script>