The method of dynamically loading css and js files with jquery is very simple,
Example
Method 1:
The code is as follows
$.getscript("test. js");
Method 2:
The code is as follows
function loadjs(file){
var head = $('head').remove('#loadscript');
$("" "").attr({src:file,type:'text/javascript',id:'load'}).appendto (head);
}
Method 3:
The code is as follows
$("" "").attr({src:file,type:'text/javascript',id:'load'}).appendto($('head').remove( '#loadscript'));
Attached below are some methods for dynamically loading js and css files.
The following code is excerpted from the code on the news.qq.com page. I have not tested it. The program seems to be fine and can be used as a reference. It is mainly used to dynamically load js files at the bottom of the web page. Go to the back of the
tag of the web page and implement it through DOM. The code is as follows:
The code is as follows
<script><br> var SCRIPT_TIMEOUT = 20000;<br>var QVPL_PATH = "/QVPL1.0.0.js";
<p>function loadHelper (jsurl) {<br>var oScriptEl, oTimeoutHDL, oHead;<br>oScriptEl = document.createElement("script");<br>oScriptEl.type = "text/javascript";<br>oScriptEl .language = "javascript";<br>oScriptEl.src = jsurl;<br>oScriptEl.onreadystatechange = doCallback;</p>
<p>oScriptEl.onload = function()<br>{<br>this.readyState = "complete";<br>doCallback();<br>if(typeof(lianbo) == "object"){<br>lianbo.init(window.QVPL);<br>}<br>};</p>
<p>oTimeoutHDL = window.setTimeout(doError,SCRIPT_TIMEOUT);<br>document.getElementsByTagName("head")[0].appendChild(oScriptEl);</p>
<p>function doCallback()<br>{<br>if (oScriptEl.readyState == "complete" || oScriptEl.readyState == "loaded")<br>{<br>oScriptEl.onload = oScriptEl.onreadystatechange = new Function();<br>window.clearTimeout(oTimeoutHDL);<br>}<br>};</p>
<p>function doError()<br>{<br>oScriptEl.parentNode.removeChild(oScriptEl);<br>};<br>}</p>
<p>loadHelper(QVPL_PATH);<br></script>