首页 > 代码库 > 网站切换主题,小demo模拟

网站切换主题,小demo模拟

我就直接抡代码了。。。

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title></title>
	<script src="http://www.mamicode.com/js/jquery-1.12.2.js"></script>
	<script>
		var pre=‘css/‘;
		$(function(){
			if(!window.sessionStorage.getItem(‘style‘) || window.sessionStorage.getItem(‘style‘)===‘‘) {
				$(‘#link‘).attr(‘href‘,pre+‘link1.css‘);
				$(‘#change‘).val(‘link1‘);
			}else {
				 $(‘#link‘).attr(‘href‘,pre+window.sessionStorage.getItem(‘style‘));
				 $(‘#change‘).val(window.sessionStorage.getItem(‘style‘));
			}
		})
	</script>
	<link rel="stylesheet" rev="stylesheet" id="link" type="text/css" media="all" href="" />
	
	<script>
		var pre=‘css/‘;
		$(function(){
			$(‘#change‘).on(‘change‘,function(){
				window.sessionStorage.setItem(‘style‘,this.value);
				location.reload(false);
			})
		})
	</script>
</head>
<body>
	<div></div>
	<select name="" id="change">
		<option value="http://www.mamicode.com/link1.css">link1</option>
		<option value="http://www.mamicode.com/link2.css">link2</option>
	</select>
</body>
</html>

  

网站切换主题,小demo模拟