[转]动态加载CSS
<script type="text/javascript">
function addStyle(stylePath) {
var container = document.getElementsByTagName("head")[0];
var addStyle = document.createElement("link");
addStyle.rel = "stylesheet";
addStyle.type = "text/css";
addStyle.media = "screen";
addStyle.href = stylePath;
container.appendChild(addStyle);
}
addStyle('https://files.cnblogs.com/wintys/dynamic.css');
</script>
function addStyle(stylePath) {
var container = document.getElementsByTagName("head")[0];
var addStyle = document.createElement("link");
addStyle.rel = "stylesheet";
addStyle.type = "text/css";
addStyle.media = "screen";
addStyle.href = stylePath;
container.appendChild(addStyle);
}
addStyle('https://files.cnblogs.com/wintys/dynamic.css');
</script>
示例页面(此页面CSS是动态加载的):http://www.cnblogs.com/wintys/archive/2013/03/21/ui_windows7_fieldset.html
示例页面动态加载的CSS文件是这个:https://files.cnblogs.com/wintys/dynamic.css
【来源】动态添加css http://www.cnblogs.com/niuniu/archive/2010/05/03/1726303.html
【参考】CSS文件动态加载 http://www.cnblogs.com/chyingp/archive/2013/03/01/load_css.html
作者:wintys (wintys@gmail.com)
出处:http://wintys.cnblogs.com
欢迎转载,转载请注明作者及出处。