以HTML格式显示HTML代码 [英] Display HTML code in HTML

查看:127
本文介绍了以HTML格式显示HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在网页上显示HTML代码片段,而无需用& lt; < c $ c>和> & gt;



换句话说,是否有一些的标签在你点击结束标签之前不会呈现HTML

解决方案

在HTML中,没有办法逃避角色。然而,在正确声明的 XHTML中(这是XML,并且需要向浏览器声明;特别是仅仅放入 DOCTYPE

 <![CDATA [您的< code>这里]] GT; 

但这只适用于XML,不适用于HTML。



在HTML中,保证在任何地方工作的唯一解决方案是转义代码(< & 分别为& lt; & amp; )。

Is there a way to show HTML code-snippets on a webpage without needing to replace each < with &lt; and > with &gt;?

In other words, is there some tag for don't render HTML until you hit the closing tag?

解决方案

In HTML proper, there’s no way short of escaping the characters. However, in properly declared XHTML (which is XML, and needs to be declared to the browser as such; in particular it’s not enough to just put in a DOCTYPE), you can use a CDATA section:

<![CDATA[Your <code> here]]>

But this only works in XML, not in HTML.

In HTML, the only solution guaranteed to work everywhere is to escape the code (< and & as &lt; and &amp;, respectively) manually.

这篇关于以HTML格式显示HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆