I need to add an link to an external css file in my header using an external javascript file. Don't ask why; I just need to do it. document.write()
doesn't work btw.
var element = document.createElement("link");
element.setAttribute("rel", "stylesheet");
element.setAttribute("type", "text/css");
element.setAttribute("href", "external.css");
document.getElementsByTagName("head")[0].appendChild(element);
另一种衬垫:
document.head.insertAdjacentHTML( 'beforeend', '<link rel=stylesheet href=/ext.css>' );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.