小编典典

在textarea内部渲染HTML

html

我需要能够在文本区域(即<strong><i><u><a>)中呈现一些HTML标记,但是textareas仅将其内容解释为文本。有没有一种简单的方法,而无需依赖外部库/插件(我正在使用jQuery)?如果没有,您知道我可以使用任何jQuery插件吗?


阅读 626

收藏
2020-05-10

共1个答案

小编典典

这与不可能textarea。您正在寻找的是一个内容可编辑的 div,这很容易做到:

<div contenteditable="true"></div>






div.editable {

    width: 300px;

    height: 200px;

    border: 1px solid #ccc;

    padding: 5px;

}



strong {

  font-weight: bold;

}


<div contenteditable="true">This is the first line.<br>

See, how the text fits here, also if<br>there is a <strong>linebreak</strong> at the end?

<br>It works nicely.

<br>

<br><span style="color: lightgreen">Great</span>.

</div>
2020-05-10