在 <head> 中动态添加链接样式表 [英] Add a link stylesheet dynamically in the <head>

查看:28
本文介绍了在 <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.

这篇关于在 <head> 中动态添加链接样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆