我需要能够在文本区域内呈现一些HTML标记(即<;strong>;、<;I>;、<;u>;、<;a>;)但是文本区域只将其内容解释为文本.有没有一种不依赖外部库/插件(我使用的是jQuery)的简单方法?
我需要能够在文本区域内呈现一些HTML标记(即<;strong>;、<;I>;、<;u>;、<;a>;)但是文本区域只将其内容解释为文本.有没有一种不依赖外部库/插件(我使用的是jQuery)的简单方法?
这在textarea
上是不可能的.你要找的是content editable 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>