disabled="disabled" 和有什么不一样?和只读=“只读"用于 HTML 表单输入字段? [英] What's the difference between disabled="disabled" and readonly="readonly" for HTML form input fields?
问题描述
我已经阅读了一些关于此的内容,但我似乎无法找到任何关于不同浏览器如何处理事物的可靠信息.
I have read a bit on this, but I can't seem to find anything solid about how different browsers treat things.
推荐答案
readonly
元素只是不可编辑,但会在相应的 form
提交时发送.disabled
元素不可编辑,也不会在提交时发送.另一个区别是 readonly
元素可以聚焦(并且在通过表单tabbing"时获得焦点)而 disabled
元素不能.
A readonly
element is just not editable, but gets sent when the according form
submits. A disabled
element isn't editable and isn't sent on submit. Another difference is that readonly
elements can be focused (and getting focused when "tabbing" through a form) while disabled
elements can't.
Read more about this in this great article or the definition by w3c. To quote the important part:
主要区别
禁用属性
- 禁用表单元素的值不会传递给处理器方法.W3C 称这是一个成功的元素.(这类似于未选中的表单复选框.)
- 某些浏览器可能会为禁用的表单元素覆盖或提供默认样式.(灰色或浮雕文字) Internet Explorer5.5 对此特别讨厌.
- 禁用的表单元素不会获得焦点.
- 在标签导航中跳过禁用的表单元素.
只读属性
- 并非所有表单元素都具有只读属性.最值得注意的是,
、
和
元素没有只读属性(虽然它们都有禁用属性)
- 浏览器不提供表单元素只读的默认覆盖视觉反馈.(这可能是个问题……见下文.)
- 设置了 readonly 属性的表单元素将被传递给表单处理器.
- 只读表单元素可以接收焦点
- 标签式导航中包含只读表单元素.
- Not all form elements have a readonly attribute. Most notable, the
<SELECT>
,<OPTION>
, and<BUTTON>
elements do not have readonly attributes (although they both have disabled attributes) - Browsers provide no default overridden visual feedback that the form element is read only. (This can be a problem… see below.)
- Form elements with the readonly attribute set will get passed to the form processor.
- Read only form elements can receive the focus
- Read only form elements are included in tabbed navigation.
这篇关于disabled="disabled" 和有什么不一样?和只读=“只读"用于 HTML 表单输入字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!