HTML:有什么方法可以在文本区域中显示图像吗?
因此,我也想在
像这样:
__________________
|Hello World |
| _______ |
| | Img | |
| | | |
| |_____| |
|Hello again. |
| _______ |
| | Img2| |
| | | |
| |_____| |
|________________|
据我所知,在 div 或任何具有 contentEditable="true"
的内容中也允许图像,但允许许多其他 HTML 标签和很多我不想要的东西:|
我只想要文本
和图像
。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用具有 contentEditable 属性的 div,其作用类似于文本区域。这就是所见即所得编辑器的创建方式。
Use a div with contentEditable attribute which acts like a textarea. That's how wysiwyg editors are created.
我知道您想编辑文本和图片,但是......为什么它必须位于文本区域内?此类控件旨在保存纯文本。有许多用 JavaScript 编写的 HTML 编辑器:
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:
简短的回答是否定的,这是不可能的,抱歉。
The short answer is no, it's not possible, sorry.
您可以使用css为textarea设置背景图片,并使用js设置文本
you can use css to set an background image for textarea, and js to set the text
您可以编写一个脚本(最好使用 PHP)来检查是否存在不需要的元素(
或
除外)。
然后您可以将用户发送回“表单”并让他再次填写,或者您可以删除整个不需要的标签。
You can write a script (ideally in PHP) which checks if there is unwanted element (another than
<p>
or<img>
).Then you can send user back to "form" and let him to fill again or you can delete the whole unwanted tags.