Html 锚点

示例

<a name="top" id="top">这里是TOP部分</a>
<a name="content" id="content">这里是CONTENT部分</a>
<a name="foot" id="foot">这里是FOOT部分</a>

 

对于如上锚点的访问有两种方法


一种是利用超链接标签<a></a>制作锚点链接,主要用于页面内的锚点访问
<a href="#top">点击我链接到TOP</a>
<a href="#content">点击我链接到CONTENT</a>
<a href="#foot">点击我链接到FOOT</a>

 

另一种方式是直接在页面地址后面加锚点标记,主要用于不同页面之间的锚点访问
假如本页面的地址是http://文件路径/index.html,要访问foot锚点只要访问如下链接即可
http://文件路径/index.html#foot

 

关于window.location.href与window.location.hash
hash是url里面#之后的部分 而href是url字符串本身
比如打开某个地址 http://www.example.com#archor
那么window.location.href就是http://www.example.com#archor
window.location.hash是#archor

你可能感兴趣的:(html)