如何在网页中添加纯文本代码? [英] How to add plain text code in a webpage?

查看:100
本文介绍了如何在网页中添加纯文本代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这是可能的,因为这个网站可以做到这一点,但我试图研究如何以及如何获得一堆垃圾,那么如何在没有浏览器将其解释为代码的情况下将标签添加到网站段落中。 b
$ b

例如,如果我有< p>< div>< / div>< / p> ,我希望在浏览器中显示div作为文本没有浏览器将其解释为html。这是复杂的吗?



我一直在为学校编写教程,如果我可以直接将代码添加到网页中,而不是以文本形式所以学生可以复制并粘贴它。


$ b

 < p>例如,如果我有< code>< p& gt;& lt; div& gt;& lt; / div& gt;& lt; / p& gt;< / code>,我希望div在浏览器中显示为文本,没有浏览器将其解释为html。这很复杂吗?< / p> 

您需要替换<和>与他们的HTML字符实体。


I know it is possible because this website does it, but I tried researching how and just got a bunch of junk, so how do I add tags to a website paragraph without the browser interpreting it as code.

For example, if I have <p><div></div></p>, I want the div to display in the browser as text not have the browser interpret it as html. Is this complicated to do?

I have been writing tutorials for school, and it would be much easier if I could add the code directly to the webpage in text form instead of images, so students can copy and paste it.

解决方案

Look at how this website itself achieves this:

<p>For example, if I have <code>&lt;p&gt;&lt;div&gt;&lt;/div&gt;&lt;/p&gt;</code>, I want the div to display in the browser as text not have the browser interpret it as html. Is this complicated to do?</p>

You need to replace the < and > with their HTML character entities.

这篇关于如何在网页中添加纯文本代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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