[Dynamic add css style]
<html> <head> <script type="text/javascript"> window.onload=function(){ var head=document.getElementsByTagName('head')[0]; //Get the head element var link=document.createElement('link'); //Create the link element node, that is, the link tag link.rel="stylesheet"; //Add rel attribute link.href="basic.css"; //Add href attribute to the link tag, the attribute value is the path of the css external link style sheet head.appendChild(link); //Add link element node to the head element child node} </script> </head> <body> <div id="div1">test</div> </body></html>[Dynamic add script tags]
The principle is the same as above
<html> <head> <script type="text/javascript"> window.onload=function(){ var head=document.getElementsByTagName('head')[0]; //Get the head element var script=document.createElement('script'); //Create script tag script.type="text/javascript"; //Add type attribute script.src="basic.js"; //Add the script tag to the child node of the script tag, and the attribute value is js path head.appendChild('script'); //Add the script tag to the child node of the head} </script> </head> <body> <div id="div1">test</div> </body></html>The above is the dynamic addition of css styles and script tags to JavaScript introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support to Wulin.com website!