[转]动态加载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>

 

 

示例页面(此页面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

posted @ 2013-03-21 16:49  wintys  阅读(717)  评论(0编辑  收藏  举报