js跳转到锚点

来源:互联网 发布:sql必知必会 第4版 pdf 编辑:程序博客网 时间:2024/06/05 02:04

1,在页面添加location.hash可实现无论哪个页面跳到该页面都跳到固定位置。

<script language="JavaScript">  

             location.hash="#navBar";  

</script>

<html>

<head>

</head>

<body>

<div id="navBar">

</div>

</body>

</html>

2,如果是点击跳转到本页某位置,<a href="#锚点id"></a>

3,如果是点击跳转到其它页某位置,<a href="lindex.html#锚点id"></a>


本文转载自:http://blog.csdn.net/liu__hua/article/details/38554955


可以做一个直观的实验,使用F12 可以查找本文html元素中有一个id是  btnDigg

你试着访问下 点击打开链接,页面自动跳到锚点位置  http://blog.csdn.net/bestcxx/article/details/52832226#btnDigg


0 0