使用HTML CSS實(shí)現(xiàn)網(wǎng)頁換膚效果(二)
發(fā)布時(shí)間:2016-01-08 14:15:13 作者:佚名
我要評(píng)論
這篇文章主要介紹了使用HTML CSS實(shí)現(xiàn)網(wǎng)頁換膚效果(二) 的相關(guān)資料,需要的朋友可以參考下
廢話不多說了,直接給大家貼html代碼了,具體代碼如下所示:
XML/HTML Code復(fù)制內(nèi)容到剪貼板
- <head>
- <title>網(wǎng)頁換膚</title>
- <meta http-equiv="Content-Type" content="text/html" ; charset="UTF-8">
- <link id="myCss" href="orange.css" rel="stylesheet">
- <script language="javascript">
- //寫入客戶端Cookie
- function writeCookie(csspath) {
- var today = new Date();
- var expires = new Date();
- expires.setTime(today.getTime() + 1000 * 60 * 60 * 24 * 30); //有效期為30天
- var str = "cssPath=" + csspath + ";expires=" + expires.toGMTString()
- + ";";
- document.cookie = str;
- }
- //讀取Cookie
- function readCookie(cookieName) {
- var search = cookieName + "=";
- if (document.cookie.length > 0) {
- offset = document.cookie.indexOf(search);
- if (offset != -1) {
- offset += search.length;
- end = document.cookie.indexOf(";", offset);
- if (end == -1) {
- end = document.cookie.length;
- return unescape(document.cookie.substring(offset, end));
- }
- }
- }
- }
- function ifCookie() {
- if (readCookie("cssPath") == undefined) {
- writeCookie("orange.css");
- }
- document.getElementById("myCss").href = readCookie("cssPath");
- }
- function change(type) {
- if (type == "orange") {
- document.getElementById("myCss").href = "orange.css";
- writeCookie("orange.css");
- }
- if (type == "gray") {
- document.getElementById("myCss").href = "gray.css";
- writeCookie("gray.css");
- }
- }
- </script>
- </head>
通過以上代碼就可以簡單實(shí)現(xiàn)使用HTML CSS實(shí)現(xiàn)網(wǎng)頁換膚效果,希望本讀代碼對(duì)大家有所幫助。
相關(guān)文章
這篇文章主要介紹了前端html換膚功能的實(shí)現(xiàn)代碼,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-08-20


