Look directly at the example.
Example 1 reload the JS file
Copy Code code 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 (He AD);
}
Example 2 reload the JavaScript file method (give JS set an ID), encapsulation into a method for everyone to use:
Copy Code code 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);
}
Example 3 jquery directly using Getscript on it.
Copy Code code 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 inside the new.js, and when clicked Click Click to run this function
});
});
});
</script>
<body>
<button type= "button" id= "Loadbutton" >load</but Ton>