Html 页面从div跳转到锚点

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17813719/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:26:58  来源:igfitidea点击:

page jump from div to an anchor

htmlanchorpage-jump

提问by Digital site

I was trying to make a div jump from <a href="#FAQ">FAQ</a>to a divid 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 从<a href="#FAQ">FAQ</a>一个divid跳转到一个id 并且可以很容易地成功,但是由于我有一个固定的链接可以跳转到,我似乎无法找到一种方法来做到这一点。

Meaning, I want a divor a hreflink to jump to a url in the same page say <a href="http://www.mydomain.ask.html">Ask</a>

意思是,我想要一个div一个 href链接跳转到同一页面中的一个 url 说<a href="http://www.mydomain.ask.html">Ask</a>

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?

我确信从一个锚点跳转<a href="#jump">jump</a>到一个 div 这样的<div id="jump">jump to point</div>工作正常。然而,相反的方式呢?它有效吗?我的意思是从 div id 跳转到锚点有效吗?

回答by Malkus

As long as your anchor has an ID you can link to a location in your view by clicking the divyou will just need some javascript.

只要您的锚点有一个 ID,您就可以通过单击链接到您视图中的某个位置,您div只需要一些 javascript。

Setting the window.location.hashvalue will put the focus of the view on the selected ID.

设置该window.location.hash值会将视图的焦点放在选定的 ID 上。

Sample

样本

<a href="#test1" id="back">Test</a>

<div id="test1" onclick="window.location.hash='back'; ">

JSFiddle Example

JSFiddle 示例

回答by Mike Phils

I think then you have to add <a href="yourid">page place</a>inside your first div and have to give id to your anchor tag <a href="yourplace" id="idname"></a>

我认为那么你必须<a href="yourid">page place</a>在你的第一个 div 中添加,并且必须为你的锚标签提供 id<a href="yourplace" id="idname"></a>

回答by YeHtunZ

if you have link to go another with variable you can use with id # sign

如果你有链接到另一个变量,你可以使用 id # 符号

<a href="product.php?action=edit#lastdiv>Go to Product Last Div</a>

<div id="lastdiv">There are last product Exist</div>