Example 1. Reload JS file
The code is as follows |
Copy Code |
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. The way to reload the JavaScript file (set an ID for JS) and encapsulate it in a way that is easy for everyone to use:
The code is as follows |
Copy Code |
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 is directly using the getscript on it.
code is as follows |
copy code |
<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</ Button> |