锚链接的三种常用方式
之前没太用过html中的锚链接,结果做项目的时候为了实现页面的内部跳转费了不少功夫,回过头才发现原来竟然有这么简单的方法,于是系统的查了一下资料,总结如下:
第一种
同一页面:定位到first <a name="first">first相关内容…… </a>
不同页面:< a href ="a.html#first">锚点在a.html页面,从其他页面跳转到a.html页面的#first处 </ a>
第二种
定位到first
<div id="first">first相关内容…… </div> //div或者span中使用id,name属性不支持
第三种
用js实现,document.location.href = "a.html#first"; //与上面类似
或者通过url传值,在取值页面通过判断传过来的值触发js函数,这里就不细说了。