链接 (Href) 到隐藏的 (display:none) html 元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12183942/
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 02:33:49  来源:igfitidea点击:

Link (Href) to a hidden (display:none) html element

htmlhrefhidden

提问by JMarques

I've a problem with anchor tags :/

我有锚标签的问题:/

I've got the following code:

我有以下代码:

<div name="divA">
<a name="A"> A</a>
</div>

<div name="divB" style="display: none;>
<a name="B"> B</a>
</div>

<div name="divHrefB">
<a href="#B">B</a>
</div>

My goal is that when i click on B (divHrefB) the application go to "divB" but since this element hidden it doesn't work.

我的目标是,当我单击 B (divHrefB) 时,应用程序会转到“divB”,但由于隐藏了该元素,因此它不起作用。

Please note, that i don't want to show divB (i want a link to the place where div are... is that possible?

请注意,我不想显示 divB(我想要一个指向 div 所在位置的链接......这可能吗?

At this point, i'm thinking on generate dynamically the href value (in this case, i would generate the following div)

此时,我正在考虑动态生成 href 值(在这种情况下,我将生成以下 div)

<div name="divHrefB">
<a href="#A">B</a>
</div>

Thanks a lot.

非常感谢。

回答by Krishna Kumar

just don't apply display: none, just add this css for the hidden div.

只是不要应用 display: none,只需为隐藏的 div 添加此 css。

<div name="divHrefB" style="height: 0px;width: 0px;overflow:hidden;">
<a href="#A">B</a>
</div>

回答by Christoph

You're missing the ending closing "comment.

你错过了结束的结束"评论。

try this guy:

试试这个人:

style="display: none;"