dqkkrt8860 2019-07-31 10:58
浏览 61
已采纳

使用包含文件的锚点?

I try to use the anchor tag with the include I have. On my Index.php I got a little "nav bar" with some anchor tags. I also included the file "text.php" in my code. This file is in the Folder "texte". The anchor tags should bring the user to the position in text.php but it only load 404 - page not found.

How I include the file:

<?php include 'texte/text.php'; ?>

I declare my "start-word" like this:

<a href=“texte/text.php#InfoAnker“>Informationen</a>

And my anchor like this:

<h2 id="InfoAnker"> Informationen </h2>

I also tried <a href=“#InfoAnker“>Informationen</a> because of the include but it came out the same result.

Any ideas?

  • 写回答

2条回答 默认 最新

  • dongshi1102 2019-07-31 11:27
    关注

    If <h2 id="InfoAnker"> Informationen </h2> is generated somewhere within your page and sent to the browser, then an anchor link should work correctly as

    <a href="#InfoAnker">Informationen</a>
    

    One think I noticed from your example is that you should make sure you use " not for quote marks - these are not the same characters, and you must use the correct one.

    Clicking on an anchor link should not result in a 404 error, if it's correctly defined. Even if the anchor ID doesn't actually exist in the page, it still wouldn't give a 404 - the worst that would occur would be that nothing would happen.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?