show HTML as plain text

邮差的信 提交于 2019-12-24 03:05:37

问题


im looking for a way to show html as html without the browser reading it, i found <plainttext> but once i start it i can't stop it for example:

<plaintext>
    <span> dobeediedabiedadadee olleeeeee</span>
</plaintext>
<h1>hi</h1>

in this example the span had to be shown as text and the h1 as a header, but the output is:

    <span> dobeediedabiedadadee olleeeeee</span>
</plaintext>
<h1>hi</h1>

</body>


</html>

here a JSFiddle link: JSFiddle

a other solution as plaintext is also welcome thanks for your time.


回答1:


plaintext has long been deprecated, just use &gt; and &lt;

&lt;span&gt; dobeediedabiedadadee olleeeeee&lt;/span&gt;

DEMO: Fiddle




回答2:


The following link describes the difficulty in using <plaintext>. long story short it is not fully supported in any browser and you should be using <pre> instead.

http://reference.sitepoint.com/html/plaintext




回答3:


You could always use javascript to escape the HTML. Here is a fiddle.

html.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");



回答4:


<plaintext> is not a pair tag. From that tag to the rest of the page, everything is interpreted as text. However, this is not standard and obsolette in HTML5:

Examples No, really. don't use it.

It is literally written in the w3 reference




回答5:


Use PRE

<pre>
    <span> dobeediedabiedadadee olleeeeee</span>
</pre>
<h1>hi</h1>



回答6:


it is compatibility issue some browser completely ignores coding of

have a look at this link http://reference.sitepoint.com/html/plaintext

i would suggest you use instead



来源:https://stackoverflow.com/questions/16717513/show-html-as-plain-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!