css3 localStorage 设计网页皮肤

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body onload="colorload();">
	<script>
		if(typeof localStorage === 'undefiend'){
			window.alert("you brower 不支持 localStorage");
		}else{
			window.alert("you brower 支持 localStorage");

			var storage = localStorage;
			function redSet(){

				var value = 'red';
				document.getElementById("divblock").style.backgroundColor = value;

				window.localStorage.setItem('DivBackGroundColor',value);
			}
			function greenSet(){
				var value="green";
				document.getElementById("divblock").style.backgroundColor = value;
				window.localStorage.setItem("DivBackGroundColor",value);
			}
			function blueSet(){
				var value = "blue";
				document.getElementById("divblock").style.backgroundColor = "blue";
				window.localStorage.setItem("DivBackGroundColor",value);
			}

			function colorload(){
				document.getElementById(
					"divblock").style.backgroundColor = window.localStorage.getItem("DivBackGroundColor");
			}
		}
	</script>
	<button id="redbtton" onclick="redSet()">红色</button>
	<button id="redbtton" onclick="greenSet()">绿色</button>
	<button id="redbtton" onclick="blueSet()">蓝色</button>
	<div id="divblock" style="width:500px;height:500px;"></div>
</body>
</html>

  

posted @ 2016-04-07 16:11  mingjixiaohui  阅读(308)  评论(0编辑  收藏  举报