为什么要在INPUT或TEXTAREA上选择可编辑的DIV [英] Why would one choose an editable DIV over an INPUT or TEXTAREA

查看:69
本文介绍了为什么要在INPUT或TEXTAREA上选择可编辑的DIV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里 多个 问题有关询问如何使div可编辑的问题。但是,可以只使用文本区域或输入字段,然后将其设置为禁用或只读。我想这会产生更好的语义。甚至在 MDN 中给出的示例看起来也很简单

There are several questions about asking how to make a div editable. However one could just use a textarea or input field and make those disabled or readonly. I would guess this would yield better semantics. Even the example given at MDN looks like a plain old input field to me.

那我为什么要使用可编辑的div?与文本区域和输入字段相比,它有什么优势?

我刚刚看过一个例子我在标签Wiki contenteditable 中找到。

I just had a look at an example I found in the tag wiki contenteditable.

这样做的好处是,我可以在可编辑的div中使用标记,但不能在textarea或输入字段中使用标记吗?那么在语义上允许孩子进入文本区域会更正确吗?或者引入一个全新的元素,就像他们对HTML5所做的一样。像 richtextarea 吗?

Is the advantage, that I can use markup inside an editable div, but not inside a textarea or an input field? Wouldn't it then be more semantically correct to allow children to a textarea. Or introduce a whole new element like they did a lot with HTML5. Something like richtextarea?

推荐答案

您的理论 richtextarea不会存在,因此当人们希望允许用户编写内容(包括格式,表格,图像等)时,他们必须使用可用的内容,而这是contentEditable的元素。

Your theorical "richtextarea" doesn't exist, so when people want to allow the users to write content including formatting, tables, images, etc... they must use what is available and that's an element with contentEditable.

当然,如果您看一个普通的 contentEditable元素会很无聊,那么您必须看一个功能齐全的编辑器,例如CKEditor或TinyMCE,它提供了基于此功能的完整界面。

Of course, if you look at a plain "contentEditable" element it will be boring, so you must look at a full featured editor like CKEditor or TinyMCE that provides a full interface built upon this feature.

这篇关于为什么要在INPUT或TEXTAREA上选择可编辑的DIV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆