admin管理员组文章数量:1333630
I have two places, the first is,<textarea></textarea>
and used to write the code.
The second is, <pre></pre>
and used to display the code.
The problem is, when write a code in the text area to display it in the second place, the code is applied and displayed as HTML element not just code as I want.
The wrong behavior:
The correct behavior (What I want):
The code:
<textarea id="inputCode" cols="50" rows="10"></textarea><br/>
<pre id="outputCode"></pre>
I have two places, the first is,<textarea></textarea>
and used to write the code.
The second is, <pre></pre>
and used to display the code.
The problem is, when write a code in the text area to display it in the second place, the code is applied and displayed as HTML element not just code as I want.
The wrong behavior:
The correct behavior (What I want):
The code:
<textarea id="inputCode" cols="50" rows="10"></textarea><br/>
<pre id="outputCode"></pre>
Share
Improve this question
edited Aug 7, 2015 at 1:46
Lion King
asked Aug 7, 2015 at 1:29
Lion KingLion King
33.8k26 gold badges90 silver badges157 bronze badges
2
- Something like this? jsfiddle/h175y2vx – Rick Hitchcock Commented Aug 7, 2015 at 1:38
- @RickHitchcock: Yes, like that. – Lion King Commented Aug 7, 2015 at 1:42
1 Answer
Reset to default 9Using innerText
to set the value of the second textarea will add the textual value only, not the HTML.
<pre id="code"></pre>
document.getElementById("code").innerText = "<input type='text' />";
Will insert in to the pre
tags,
<input type='text' />
Example
JSFiddle
本文标签: javascriptHow to write a code inside ltpregt tag without apply the codeStack Overflow
版权声明:本文标题:javascript - How to write a code inside <pre> tag without apply the code - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742343785a2457113.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论