在 <head> 中动态添加链接样式表
如何在文档头部添加链接样式表引用?
How to add a link stylesheet reference to the head of a document ?
我找到了这段代码,但它不适用于所有浏览器,它使我的 IE7 崩溃:
I've found this code but it's not working with all browsers, it crashes my IE7 :
var ss = document.createElement("link");
ss.type = "text/css";
ss.rel = "stylesheet";
ss.href = "style.css";
document.getElementsByTagName("head")[0].appendChild(ss);
谢谢
推荐答案
这是一个简单的交叉引用 javascript 错误.祝你有美好的一天.
That was a simple cross reference javascript bug. Have a nice day.
相关文章