一、网页换肤

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>网页换肤</title>
		<script type="text/javascript">
		   
		    //检查浏览器是否支持localStorage

			if(typeof localStorage==='undefined'){
				window.alert("not support localStorage");				
			}else{
				window.alert("support localStorage");
				var storage = localStorage;
				//设置DIV背景颜色为红色,并保存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 = value;
					window.localStorage.setItem("DivBackGroundColor",value);
				}
				
				function colorload(){
					document.getElementById("divblock").style.backgroundColor = window.localStorage.getItem("DivBackGroundColor");
				}
			}
		</script>
	</head>
	<body onload="colorload()">
		<section >
			<button >红色</button>
			<button >绿色</button>
			<button >蓝色</button>
			<div ></div>
		</section>
	</body>
</html>

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-01-18
  • 2021-08-15
  • 2021-09-28
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-11-07
  • 2021-09-30
  • 2021-12-22
  • 2022-12-23
  • 2021-10-04
  • 2021-09-01
相关资源
相似解决方案