使用JS在運行中動態替換CSS樣式表

來源:互聯網
上載者:User
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>無標題頁</title>
    <link href="" type="text/css" rel="Stylesheet" />

    <script type="text/javascript">
        var $=function(id){return document.getElementById(id);}
        function SelectSkin()
        {
            if($("selSkin"))
            {
                var skinname = $("selSkin").options[$("selSkin").selectedIndex].text;
                var filename = "css/" + skinname + ".css";
                var ctrlLink = document.getElementsByTagName("link")[0];
                ctrlLink.setAttribute("href", filename);
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div id="divbody">
        <div id="main">
            <div id="used">
                <span>Skin選擇</span>
                <select onchange="SelectSkin()" id="selSkin">
                    <option>Red</option>
                    <option>Blue</option>
                </select>

            </div>
        </div>

    </div>
    </form>
</body>
</html>
相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.