这篇文章主要为大家展示了“如何使用HTML和CSS实现网页换肤效果”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下“如何使用HTML和CSS实现网页换肤效果”这篇文章吧。
具体代码如下所示:
<head>
<title>网页换肤</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>
以上是“如何使用HTML和CSS实现网页换肤效果”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注编程网行业资讯频道!