-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
52 lines (47 loc) · 1.25 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
.page {
display: none;
}
.home-page {
display: block;
}
</style>
</head>
<body>
<nav>
<span onclick="changePage('home')">home</span> |
<span onclick="changePage('list')">list</span> |
<span onclick="changePage('about')">about</span>
</nav>
<div class="page home-page">I am homepage</div>
<div class="page list-page">I am list</div>
<div class="page about-page">About me </div>
</body>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script>
// 非常粗糙的初始化,請勿使用在 production
if (location.href.indexOf('/home') >=0 ) {
changePage('home')
} else if (location.href.indexOf('/list') >= 0) {
changePage('list')
} else if (location.href.indexOf('/about') >= 0) {
changePage('about')
}
function changePage(page) {
$('.page').hide()
if (page === 'home') {
$('.home-page').show()
} else if (page === 'list') {
$('.list-page').show()
} else if (page === 'about') {
$('.about-page').show()
}
// 精華所在
history.pushState(null, null, page)
}
</script>
</html>