结论:用转义字符
例1:想在页面显示<br>
代码为:
<code class="hljs perl has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">&<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">lt</span>;br&<span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">gt</span>;</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
将<和>分别写成了转义字符的形式。
常用转义字符表为:
显示结果 | 描述 | 实体名称 | 实体编号 |
---|
| 空格 | |   |
< | 小于号 | < | < |
> | 大于号 | > | > |
& | 和号 | & | & |
“ | 引号 | " | " |
‘ | 撇号 | '(IE不支持) | ' |
例2:想显示转义字符:<
代码为:
<code class="hljs bash has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: "Source Code Pro", monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">&<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">#60;</span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right: 1px solid rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li></ul>
将&写成了转义字符的形式。