使用JavaScript添加外部样式表 [英] Adding External Stylesheet using JavaScript
本文介绍了使用JavaScript添加外部样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用外部javascript文件在标头中添加指向外部css文件的链接.不要问为什么;我只需要这样做. document.write()
不能正常工作.
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);
这篇关于使用JavaScript添加外部样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文