jquery换肤

<script src="script/jquery-2.1.0.js"></script>  
    <link href="style/green.css" rel="stylesheet" id="theme" />  
    <script type="text/javascript">  
        $(function () {  
            $("button").click(function () {  
                var themecss = $("#theme");  //link元素的id
                themecss.attr("href", "style/blue.css");  
                //或者  
                var themeCSS = document.getElementById('theme');  
                themeCSS.href = "style/blue.css";  
                  
            });  
        });  
    </script>

最终效果是:假设左上角有3个切换皮肤的按钮,点击不同的按钮,将切换不同的皮肤。没有设置cookie皮肤记忆,所以当刷新的时候,还是会回到默认的皮肤,大家喜欢的话可以再往精致的地方做一下。

原文地址:https://www.cnblogs.com/koleyang/p/4707431.html