网页换肤

  1. 在script标签中编写保存cookie信息的方法,用于将CSS样式的文件的路径信息保存到客户端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;
	}
  1. 编写读取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));
		         } 			
        } 		
    } 	
}
  1. 编写超链接的onClick事件调用的方法
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");
		}
	}

index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>统一样式页面</title>
<link id="myCss" href="orange.css" rel="stylesheet">
</head>
<body>
<a href="#" onclick="change('orange')">[橘色]</a>
<a href="#" onclick="change('gray')">[灰色]</a>
<from action="">
	<table align="center">
		<tr>
			<td>用户名:</td><td><input type="text" name="name"></td>
		</tr>
		<tr>
			<td>密码:</td><td><input type="password" name="pwd"></td>
		</tr>
		<tr>
			<td>确认密码</td><td><input type="password" name="pwd1"></td>
		</tr>
		<tr>
			<td>姓名:</td>
			<td>
				<input type="radio" name="sex" value="m">男
				<input type="radio" name="sex" value="f">女
		   	</td>
		 </tr>
		 <tr>
		 	<td>年龄</td><td><input type="text" name="age"></td>
		 </tr>
		 <tr>
		 	<td><input class="botton1" type="submit" value="注册"></td>
		 	<td><input class="botton2" type="button" value="重置"></td>
		 </tr>
	</table>
</from>

<script type="text/javascript">
	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;
	}
	
	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 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>
</body>
</html>

orange.css

body{
margin:2em;
	background-color:#FF9900;
}
td{
	font-family:"Times New Roman",Times,serif;
	font-size:14px;
		font-weight:bold;
}
input{
	font-size:9pt;
	color:#003399;
	font-family:宋体;
	border:'1px' 'dashed' '#999999';
	background:#EEEEEE;
}
.td1{
	font-size:12pt;
	font-family:黑体;
}
.botton1{
	background:#FFFFFF;
	font-weight:bold;
	width:50px;
}

gray.css

body{
margin:2em;
	background-color:#999999;
}
td{
	font-family:"Times New Roman",Times,serif;
	font-size:14px;
		font-weight:bold;
}
input{
	font-size:9pt;
	color:#003399;
	font-family:宋体;
	border:'1px' 'dashed' '#999999';
	background:#EEEEEE;
}
.td1{
	font-size:12pt;
	font-family:黑体;
}
.botton1{
	background:#FFFFFF;
	font-weight:bold;
	width:50px;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值