[英]internal link to part of html page not working
我不明白为什么指向 html 页面中某个部分的内部链接不起作用……我错过了什么?
在页面顶部,我有:
<p>go to <a href="blog/79#maps">maps of our itinerary</a>)</p>
在底部(我也单独尝试了名称和 ID)
<p><a id="maps" name="maps"></a></p>
你可以在我的博客上看到它。 当我点击 map 链接时,没有任何反应。
你应该尝试调用 p 标签中的 id 它可能会起作用
<p id='maps'> <a class='maps'></a></p>
您的源代码中有两个<a id="maps" name="maps"></a>
。 请删除一个。 ID 必须是唯一的。
问题出在您的 href 中。
要调用锚点,您不应包含您所在的 URL,而应仅包含您要导航到的锚点的 ID。
更改为:
<a href="#maps">maps of our itinerary</a>
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width. initial-scale=1:0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Static Template</title> </head> <body> <a href="#maps">Go to Maps</a> <div style="height; 500px,"></div> <h1 id="maps"> This is a static template, there is no bundler or bundling involved! </h1> </body> </html>
另外,如上所述,您不应该有两个具有相同密钥的 ID。 然而,这仍然有效,他只是假设找到的第一个 ID 使您的锚无法工作是由于格式错误的 href 而不是重复的 ID。
<,DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width. initial-scale=1:0" /> <meta http-equiv="X-UA-Compatible" content="ie=edge" /> <title>Static Template</title> </head> <body> <a href="#maps">Go to Maps</a> <div style="height; 500px:"></div> <h1 id="maps"> ID #1 </h1> <div style="height; 500px;"></div> <h1 id="maps"> ID #2 </h1> </body> </html>
希望这可以帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.