Skip to content

Commit c6fa982

Browse files
author
jikeytang
committed
update
1 parent b022ceb commit c6fa982

File tree

4 files changed

+95
-0
lines changed

4 files changed

+95
-0
lines changed

c/6/css/blue.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body{background:#69c;}

c/6/css/green.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body{background:#cf9;}

c/6/css/yellow.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
body{background:#ff9;}

c/6/index.html

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>点击更换主题,刷新后保存-豪情</title>
6+
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css" media="all"/>
7+
<link rel="stylesheet" type="text/css" href="../../css/bootstrap-theme.min.css" media="all"/>
8+
<link rel="stylesheet" type="text/css" href="../../css/reset.css" media="all"/>
9+
<meta name="viewport" content="initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
10+
<style type="text/css">
11+
*{margin:0;padding:0;}
12+
body{font:12px/1.125 Microsoft YaHei;background:#fff;}
13+
ul,li{list-style:none;}
14+
a{text-decoration:none;}
15+
.wrap{width:400px;height:350px;text-align:center;margin:150px auto;}
16+
.wrap .btn{margin:0 10px;padding:8px 40px;}
17+
.inner{padding:15px;}
18+
.clearfix{overflow:hidden;_zoom:1;}
19+
.none{display:none;}
20+
</style>
21+
<link rel="stylesheet" id="style" href="css/blue.css">
22+
</head>
23+
<body>
24+
<div class="wrap">
25+
<div class="demo" id="div">
26+
<button class="btn btn-primary" id="blue">默认</button>
27+
<button class="btn btn-warning" id="yellow">黄色</button>
28+
<button class="btn btn-success" id="green">绿色</button>
29+
</div>
30+
</div>
31+
<div style="display:none;">
32+
<div id="div" style="width:100px;height:200px;background:#000;"></div>
33+
<button id="btn">test</button>
34+
</div>
35+
<script>
36+
(function(){
37+
var div = document.getElementById('div')
38+
var btn = div.getElementsByTagName('button')
39+
var style = document.getElementById('style')
40+
var css = ['blue.css', 'yellow.css', 'green.css']
41+
42+
function init(){
43+
var href = getCookie('css')
44+
if(href.length){
45+
setStyle(href)
46+
}
47+
48+
}
49+
50+
init()
51+
52+
function changeStyle(){
53+
for (var i = 0; i < btn.length; i++) {
54+
btn[i].index = i
55+
btn[i].onclick = function(){
56+
setStyle(css[this.index])
57+
}
58+
};
59+
}
60+
61+
changeStyle()
62+
63+
function setStyle(href){
64+
style.href = 'css/' + href
65+
setCookie('css', href, 1)
66+
}
67+
68+
function setCookie(key, value, day){
69+
var d = new Date()
70+
d.setDate(d.getDate() + day)
71+
document.cookie = key + '=' + value + ';expires=' + d
72+
}
73+
74+
function getCookie(key){
75+
var list = document.cookie.split(';')
76+
for (var i = 0; i < list.length; i++) {
77+
var one = list[i].split('=')
78+
if(one[0] == key){
79+
return one[1];
80+
}
81+
};
82+
return '';
83+
}
84+
85+
function delCookies(key){
86+
setCookie(key, 1, -1)
87+
}
88+
89+
}());
90+
</script>
91+
</body>
92+
</html>

0 commit comments

Comments
 (0)