使其他标签呈现为纯文本的HTML标签

我想在一个页面添加一个区域,其中所有动态内容都以纯文本而不是标记呈现.例如:
<myMagicTag>
      <b>Hello</b> World
  </myMagicTag>

我想要< b>标签显示为只是文本,而不是作为一个大胆的指令.我宁愿不必编写代码来转换每个“<”到“&”. 我知道< textarea>会做,但它有其他不利的副作用,如添加滚动条.

myMagicTag是否存在?

编辑:这样做的jQuery或javascript函数也可以.不能做服务器端,不幸的是.

解决方法

您可以使用 script element(由我粗体):

The script element allows authors to include dynamic script and data blocks in their documents.

例:

<script type="text/plain">
This content has the media type plain/text,so characters reserved in HTML have no special meaning here: <div> ← this will be displayed.
</script>

(请注意,脚本元素的允许内容restricted,例如can’t将< / script>作为文本内容(将关闭脚本元素))

通常,脚本元素在浏览器的CSS中显示:none,因此您需要在CSS中覆盖,例如:

script[type="text/plain"] {display:block;}

相关文章

vue阻止冒泡事件 阻止点击事件的执行 &lt;div @click=&a...
尝试过使用网友说的API接口获取 找到的都是失效了 暂时就使用...
后台我拿的数据是这样的格式: [ {id:1 , parentId: 0, name:...
JAVA下载文件防重复点击,防止多次下载请求,Cookie方式快速简...
Mip是什么意思以及作用有哪些