HTML:有没有办法在文本区域中显示图像?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3793090/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
HTML : Is there any way to show images in a textarea?
提问by Adam
So I want to show image thumbnails
too in the <textarea>
along with text. If you know a javascript solution that's perfect too(if possible in vanilla JS).
所以我也想image thumbnails
在<textarea>
文本中显示。如果你知道一个完美的 javascript 解决方案(如果可能的话在 vanilla JS 中)。
Like this:
像这样:
__________________
|Hello World |
| _______ |
| | Img | |
| | | |
| |_____| |
|Hello again. |
| _______ |
| | Img2| |
| | | |
| |_____| |
|________________|
As I know and seen in a div or anything what has contentEditable="true"
allows image too but, allows many other HTML tags and a lots of things what I don't want :|
正如我在 div 或任何contentEditable="true"
允许图像但允许许多其他 HTML 标签和许多我不想要的东西中看到的那样:|
I want just text
and images
.
我只想text
和images
。
回答by Hussein
Use a div with contentEditable attribute which acts like a textarea. That's how wysiwyg editors are created.
使用具有 contentEditable 属性的 div,其作用类似于 textarea。这就是所见即所得编辑器的创建方式。
div {
width: 300px;
height: 200px;
border: 1px solid #ccc;
}
<div contentEditable="true">Type here. You can insert images too
<img src="http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzKk7Ilj2zQ0CS6PbOkq7ZhRInnNd1Yz3TQzU4e&t=1" />
</div>
回答by álvaro González
I understand you want to edit text and pictures but... why does it have to be inside a textarea? Such control is designed to hold plain text. There're many HTML editors written in JavaScript:
我知道您想编辑文本和图片,但是...为什么它必须在 textarea 内?此类控件旨在保存纯文本。有许多用 JavaScript 编写的 HTML 编辑器:
回答by thomasmalt
The short answer is no, it's not possible, sorry.
简短的回答是否定的,这是不可能的,抱歉。
回答by yangqi
you can use css to set an background image for textarea, and js to set the text
可以使用css为textarea设置背景图片,使用js设置文本