【问题标题】:How can i use a href function to move cursor to a particular part of the page如何使用 href 函数将光标移动到页面的特定部分
【发布时间】:2017-11-13 06:12:14
【问题描述】:
【问题讨论】:
标签:
javascript
jquery
html
url
tags
【解决方案1】:
href 属性获取您要链接到的页面的 url。但您也可以在单击链接时指向页面的特定部分。
假设您在页面上,并且希望在单击链接时跳转到页脚而不重新加载页面。简单地做
<a href="#footer">click here to go to footer</a>
只需在页脚 div 中添加一个 id 页脚,工作就完成了……
您将看到网址更改为http://previous/url/of/page#footer
<div id="footer"> footer section </div>
*note -> 使用 '#' 作为 id 和 '.'上课。
【解决方案2】:
如果您使用永久链接,则光标将被移动到页面的该部分。例如。
<div> <a href="#next">If you click this permalink</a></div>
<div id="next"> You will land here</div>
差不多就是这样。它适用于内容过多的网站,但您希望阻止访问者根据他们的兴趣离开。