View the instance directly.
Example 1 reload the js File
Copy codeThe Code is as follows:
Function loadJs (file ){
Var head = $ ("head"). remove ("script [role = 'reload']");
$ ("<Scri" + "pt>" + "</scr" + "ipt> "). attr ({role: 'reload', src: file, type: 'text/javascript '}). appendTo (head );
}
Example 2 How to reload a javascript file (set an id for js) and encapsulate it into a method for your convenience:
Copy codeThe Code is as follows:
Function reloadAbleJSFn (id, newJS)
{
Var oldjs = null;
Var t = null;
Var oldjs = document. getElementById (id );
If (oldjs) oldjs. parentNode. removeChild (oldjs );
Var scriptObj = document. createElement ("script ");
ScriptObj. src = newJS;
ScriptObj. type = "text/javascript ";
ScriptObj. id = id;
Document. getElementsByTagName ("head") [0]. appendChild (scriptObj );
}
In Example 3, jquery directly uses getScript.
Copy codeThe Code is as follows:
<Script type = "text/javascript" src = ".../jquery. js"> </script>
<Script type = "text/javascript">
$ (Function ()
{
$ ('# LoadButton'). click (function (){
$. GetScript ('new. js', function (){
NewFun ('"Checking new script"'); // This function is in new. js. click it to run this function.
});
});
});
</Script>
</Head>
<Body>
<Button type = "button" id = "loadButton"> Load </button>