<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<div>
<button type="button" class="small">小</button>
<button type="button" class="big">大</button>
<div class="d1"></div>
</div>
<script type="text/javascript">
var small = document.querySelector(".small");
var big = document.querySelector(".big");
var d1 = document.querySelector(".d1");
small.onclick = function(){
location.href = "02_hash值改变的事件.html#small";
}
big.onclick = function(){
location.href = "02_hash值改变的事件.html#big";
}
window.onhashchange = function(){
var hash = location.hash.slice(1);
if(hash == "small"){
d1.innerHTML = "这是small";
}else if(hash == "big"){
d1.innerHTML = "这是big";
}
}
</script>
</body>
</html>
JS:hash值改变的事件(代)
最新推荐文章于 2024-11-07 09:50:43 发布