简体   繁体   English

在文本区域内插入html

[英]Insert html inside text area

I have 我有

<textarea rows="20" cols="100"></textarea>

When i insert html 当我插入HTML

document.getElementsByTagName('textarea').value = "<p>Content</p>";

The html does not get rendered inside the <textarea /> html不会在<textarea />内部呈现

Is there a way to render html inside textarea? 有没有一种方法可以在textarea内部呈现html?

getElementsByTagName returns a collection of elements (like an array), so you have to specify the index of the one you want. getElementsByTagName返回元素的集合(如数组),因此您必须指定所需元素的索引。 If you only have one use [0] 如果您只有一种用途[0]

document.getElementsByTagName('textarea')[0].value = "<p>Content</p>";

jsFiddle example jsFiddle示例

Note that you can't render HTML in a textarea though, only text. 请注意,尽管如此,您不能在文本区域中呈现HTML,只能呈现文本。

You cannot render HTML inside a text area as it is for input. 您不能在文本区域内渲染HTML,因为它是用于输入的。 You can only render text 您只能渲染文本

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM