jquery+css實現網頁顏色主題變換(只改變已設定好的幾種顏色主題)

來源:互聯網
上載者:User

標籤:預設顏色   lin   query   傳值   html   blur   pre   enter   require   

又遇到顏色主題變化,這次使用了jquery+css,使用了函數傳值,而不是之前網站換膚改變link的方法。

首先是設定好顏色主題後,點擊改變頁面顏色主題。(需要自行匯入jquery.js後查看效果)

直接貼代碼:

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <script type="text/JavaScript" src="js/jquery.js"></script></head><style>    div section{         width: 30px;         height: 30px;         margin: 10px;         display: inline-block;     }    div section:nth-of-type(1){         background-color: #177cb0;     }    div section:nth-of-type(2){         background-color: #db5a6b;     }    div section:nth-of-type(3){         background-color: #008000;     }    div section:hover{         cursor:pointer;    }</style><body>    <div>        <section onclick="blue()"></section>        <section onclick="red()"></section>        <section onclick="green()"></section>    </div>        <center>        <h2 style="display:inline-block;">顏色主題jquery變換</h2>        <form action="" id="simpleCalc">            <span>input:</span><input type="text" required><br><br>            <button id="calc">確認</button>        </form>        <span id="result"></span>    </center>    <script>      //設定預設顏色主題        $(document).ready(function(){            blue();        });        // 點擊單個換色        function blue(){            change("#177cb0");        }        function red(){            change("#db5a6b");        }        function green(){            change("#008000");        }        //設定需要改變顏色的元素及其樣式        function change(colo){            $("#calc").css("background-color", colo);            $("h2, span").css("color", colo);            $("input").css("color", colo);            $("input[type=text]").focus(function(){$(this).css("outline", "none")});            $("input[type=text]").focus(function(){$(this).css("border", "2px solid " + colo)});            $("input[type=text]").blur(function(){$(this).css("border", "1px solid gray")});        }    </script></body></html>    

下一篇貼即時變化顏色主題(通過input輸入顏色值進行改變)的代碼。

如有錯誤,請您指正!

jquery+css實現網頁顏色主題變換(只改變已設定好的幾種顏色主題)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.