如何在网页上显示 HTML 代码(实体)?

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

How do I display HTML code (entities) on a web page?

html

提问by Kevin Li

how do you write html code so the user and see it on a webpage (like a how-to for html)

你如何编写 html 代码以便用户在网页上看到它(就像 html 的操作方法)

回答by knittl

encode your html entities:

编码您的 html 实体:

< … &lt;
> … &gt;
& … &amp;
" … &quot;
(' … &apos; xml, not html. see comments)

you might also want to use

您可能还想使用

<pre><code>
here comes your preformatted and escaped &lt;html&gt;-code
</code></pre>

to have your code monospaced and preserve whitespaces

让您的代码等宽并保留空格

回答by Jonathan Patt

You have to use HTML character entities &lt;and &gt;in place of the < and > symbols so they aren't interpreted as HTML tags.

你必须使用HTML字符实体&lt;&gt;代替<和>符号,以便它们不会被解释为HTML标签。

回答by Imagist

To avoid issues with &apos;, use &#39;.

为避免出现问题&apos;,请使用&#39;.