我已经编写了Javascript来动态地将css应用到页面。
var css = 'body {background-color:#111;}';
var themeCssNode = document.getElementById('theme_css');
if (themeCssNode) {
themeCssNode.parentNode.removeChild(themeCssNode);
}
themeCssNode = document.createElement('style');
themeCssNode.type = 'text/css';
themeCssNode.id = 'theme_css';
document.getElementsByTagName('head')[0].appendChild(themeCssNode);
if (themeCssNode.styleSheet) {
themeCssNode.styleSheet.cssText = css;
} else {
var cssText = document.createTextNode(css);
themeCssNode.appendChild(cssText);
}
以上javascript在所有浏览器中都运行良好,但在Safari中不起作用。我尝试了各种组合,但没有运气,所以最后想到把它放在这里让专家帮忙。
非常感谢你。