網站切換主題,小demo模擬

我就直接掄代碼了。。。css

<!doctype html>
<html lang="en">
<head>
	<meta charset="UTF-8" />
	<title></title>
	<script src="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="link1.css">link1</option>
		<option value="link2.css">link2</option>
	</select>
</body>
</html>
相關文章
相關標籤/搜索