开发者

How to show literal HTML script in a web page?

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开发者_运维知识库>

How can I do that?


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>            


You'll need to encode the angle brackets etc in order to show this on the page.

You can do this manually in html as:

&lt;a href="#"&gt;test&lt;/a&gt;

Where:

&lt; = <

&gt; = >

For other characters here's a table of character codes: http://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜