簡體   English   中英

html 部分頁面的內部鏈接無效

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM