如何在网页中显示文字HTML脚本?

问题描述:

我有一些HTML脚本,希望将其显示在网页上,例如此处的代码选项:

I have some HTML script that I would like to make it display in a web page like the code option here:

<a href="#">test</a>

我该怎么做?

您需要对文本进行HTML转义,因为您可以轻松判断是否查看了此页面的HTML源代码:

You need to HTML-escape your text, as you can easily tell if you look at the HTML source of this very page:

<div class="post-text">
    <p>I have some HTML that I would like to make it appear like the code option here</p>

    <pre><code>&lt;a href="#"&gt;test&lt;/a&gt;
    </code></pre>

    <p>How can I do it?</p>
</div>