-
Notifications
You must be signed in to change notification settings - Fork 240
/
Copy pathdemo5.html
34 lines (31 loc) · 844 Bytes
/
demo5.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
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<link rel="stylesheet" href="./css/quick_layout.css"/>
<script src="./js/jquery.js"></script>
</head>
<body>
<div class="tc">
通过pushState改变hash:
</div>
<div class="tc mt10 mb10">
<button type="button" onclick="pushState({},'#1');">pushState({},'#1')</button>
<button type="button" onclick="replaceState({},'#2');">replaceState({},'#2')</button>
</div>
<div id="log" class="tc">
</div>
<script>
function pushState(state, page) {
history.pushState(state, '', page);
}
function replaceState(state, page) {
history.replaceState(state, '', page);
}
window.onhashchange = function(event){
$('#log').html('当前网页的hash:' + location.hash);
}
</script>
</body>
</html>