如何在网页上显示 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
How do I display HTML code (entities) on a web page?
提问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 实体:
< … <
> … >
& … &
" … "
(' … ' xml, not html. see comments)
you might also want to use
您可能还想使用
<pre><code>
here comes your preformatted and escaped <html>-code
</code></pre>
to have your code monospaced and preserve whitespaces
让您的代码等宽并保留空格
回答by Jonathan Patt
You have to use HTML character entities <
and >
in place of the < and > symbols so they aren't interpreted as HTML tags.
你必须使用HTML字符实体<
和>
代替<和>符号,以便它们不会被解释为HTML标签。
回答by Imagist
To avoid issues with '
, use '
.
为避免出现问题'
,请使用'
.