页面从div跳到锚点 [英] page jump from div to an anchor
问题描述
我试图从< a href =#FAQ> FAQ< / a>
跳转到 div
id,并且可以轻松获得成功,但由于我有一个固定的链接跳转到,我似乎无法找到如何做到这一点。
I was trying to make a div jump from <a href="#FAQ">FAQ</a>
to a div
id and could success easily, but since I have a fixed link to jump to, I can't seem to find a way how to do that.
这意味着,我希望 div 或 href 链接跳转到同一页面中的网址,例如< a href =http ://www.mydomain.ask.html>询问< / a>
Meaning, I want a div or a href link to jump to a url in the same page say <a href="http://www.mydomain.ask.html">Ask</a>
我知道确切地说,作为< a href =#jump>跳转< / a>
转换为div,例如< div id =jump> ;跳转到指向< / div>
正常工作。但是,相反的方式呢?它工作吗?我的意思是从div id跳到一个锚点?
I know for sure that jumping from an anchor such as <a href="#jump">jump</a>
to a div such as <div id="jump">jump to point</div>
works fine. However, how about the opposite way? does it work? I mean jumping from div id to an anchor works?
推荐答案
只要您的锚点有一个ID,您可以链接到一个位置在你的视图中点击 div
,你只需要一些javascript。
As long as your anchor has an ID you can link to a location in your view by clicking the div
you will just need some javascript.
设置 window.location.hash
值会将视图的焦点放在所选ID上。
Setting the window.location.hash
value will put the focus of the view on the selected ID.
示例
<a href="#test1" id="back">Test</a>
<div id="test1" onclick="window.location.hash='back'; ">
这篇关于页面从div跳到锚点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!