If you load the script tag directly with jquery append, you will get an error. In addition to document.write, there are other better ways to dynamically load JS files.
1,jquery method
$.getscript ("./test.js"); Load JS file
$.getscript ("./test.js", function () {//Load test.js, after success, and execute callback function
Console.log ("Load JS file");
});
2,js method
<body>
</body>
<script type= "Text/javascript" >
function Loadscript (URL, callback) {
var script = document.createelement ("script");
Script.type = "Text/javascript";
if (typeof (callback)!= "undefined") {
if (script.readystate) {
Script.onreadystatechange = function () {
if (script.readystate = = "Loaded" | | | script.readystate = = "complete") {
Script.onreadystatechange = null;
Callback ();
}
};
} else {
Script.onload = function () {
Callback ();
};
}
}
script.src = URL;
Document.body.appendChild (script);
}
Loadscript ("Http://code.jquery.com/jquery-latest.js", function () {//load, and execute callback function
Alert ($ (window). Height ());
});
Loadscript ("Http://code.jquery.com/jquery-latest.js"); Load JS file
</script>