js筑基之锚点

获取元素 绑定事件
 

<script type="text/javascript">
	window.onload=function(){
		btn=document.getElementById("btn");
		btn.onclick=function(){
			location.hash="#top";
		}
	}
</script>
<body>
	<div style="height: 500px;background: #f00" id="top"></div>
	<div style="height: 500px;"></div>
	<input type="button" id="btn" value="返回顶部">
</body>

猜你喜欢

转载自blog.csdn.net/qq_39370495/article/details/86644194