Asynchronously loading js files or asynchronously loading js modules, supports all browsers, including IE, reference to JavaScript advanced programming
1.CreateScript method is used to create a script tag and add it to the body tag
2.The createModule method is used to create a tag for a script script, and if it is run under IE8, an exception will be thrown. The script content compatible with IE-added js is executed in the exception capture module.
<button >jsdocument</button> <button >jsModule</button> <script type="text/javascript"> //Asynchronously loading files, supporting all browsers ("demo").onclick = function () { createScript("../../js/jquery-1.8."); } function createScript(url) { var script = ("script"); = "text/javascript"; = url; (script); } //The standard DOM method will be tried first, because except for IE (the error will be thrown in IE), all browsers support this method. If an error is thrown, it means it is IE, so you must use the tezt attribute. ("demo1").onclick = function () { createModule("function sayHi(){alert('Hi !')}"); } function createModule(code) { var script = ("script"); = "text/javascript"; try { ((code)); } catch (ex) { (code); } (script); } </script>
The above is all the simple methods to add javascript dynamic scripts brought to you by the editor. I hope everyone supports me~