HTML : Is there any way to show images in a textarea?

依然范特西╮ 提交于 2019-12-17 06:37:14

问题


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).

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 :|

I want just text and images.


回答1:


Use a div with contentEditable attribute which acts like a textarea. That's how wysiwyg editors are created.

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>



回答2:


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:

  • http://ckeditor.com/
  • http://tinymce.moxiecode.com/
  • http://www.openwebware.com/
  • http://www.unverse.net/whizzywig-cross-browser-html-editor.html
  • http://www.htmlarea.com/
  • ...



回答3:


The short answer is no, it's not possible, sorry.




回答4:


you can use css to set an background image for textarea, and js to set the text



来源:https://stackoverflow.com/questions/3793090/html-is-there-any-way-to-show-images-in-a-textarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!