Jquery dynamically loads css. js files are easy to use,
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 ');
$ ("<Scri" + "pt>" + "</scr" + "ipt> "). attr ({src: file, type: 'text/javascript ', id: 'load '}). appendto (head );
}
Method 3:
The Code is as follows:
$ ("<Scri" + "pt>" + "</scr" + "ipt> "). attr ({src: file, type: 'text/javascript ', id: 'load '}). appendto ($ ('head '). remove ('# loadscript '));
The following describes how to dynamically load js and css files using js.
The following code is taken from the code on the news.qq.com page. I did not perform the test. The program looks like there should be no problem. It can be used as a reference and is mainly used at the bottom of the webpage, the Code is as follows:
The Code is as follows:
<Script>
Var SCRIPT_TIMEOUT = 20000;
Var QVPL_PATH = "/QVPL1.0.0.js ";
Function loadHelper (jsurl ){
Var oScriptEl, oTimeoutHDL, oHead;
OScriptEl = document. createElement ("script ");
OScriptEl. type = "text/javascript ";
OScriptEl. language = "javascript ";
OScriptEl. src = jsurl;
OScriptEl. onreadystatechange = doCallback;
OScriptEl. onload = function ()
{
This. readyState = "complete ";
DoCallback ();
If (typeof (lianbo) = "object "){
Lianbo. init (window. QVPL );
}
};
OTimeoutHDL = window. setTimeout (doError, SCRIPT_TIMEOUT );
Document. getElementsByTagName ("head") [0]. appendChild (oScriptEl );
Function doCallback ()
{
If (oScriptEl. readyState = "complete" | oScriptEl. readyState = "loaded ")
{
OScriptEl. onload = oScriptEl. onreadystatechange = new Function ();
Window. clearTimeout (oTimeoutHDL );
}
};
Function doError ()
{
OScriptEl. parentNode. removeChild (oScriptEl );
};
}
LoadHelper (QVPL_PATH );
</Script>