动态CSS加载在IE将不工作 [英] dynamic CSS loading in IE won't work
本文介绍了动态CSS加载在IE将不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的页面中有一个按钮,并且onclick事件,如果应该附加到服务器的< head>
一个CSS文件,并做别的事。
它在FF中工作完美,但在IE,它似乎无法工作(它附加< link>
到< head>
- 但是CSS不会影响元素)
I have a button in my page, and onclick event, if should append to the <head>
a CSS file from a server and do something else.
it works perfectly in FF but in IE, it seems not to work (it did append the <link>
to the <head>
- but the CSS won't affect the elements)
回到我目前的代码:
function loadDynamicCss(filename) {
var fileref = document.createElement("link")
fileref.setAttribute("rel", "stylesheet")
fileref.setAttribute("type", "text/css")
fileref.setAttribute("href", filename)
document.getElementsByTagName("head")[0].appendChild(fileref);
}
是什么原因导致的?
谢谢!
推荐答案
尝试此功能:
function include_css(url) {
var page = document.getElementsByTagName('head')[0],
cssElem = document.createElement('link');
cssElem.setAttribute('rel', 'css');
cssElem.setAttribute('type', 'text/css');
cssElem.setAttribute('href', url);
page.appendChild(cssElem);
}
这篇关于动态CSS加载在IE将不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文