disabled=“disabled"有什么区别?和只读=“只读";对于 HTML 表单输入字段?

2022-01-30 00:00:00 html cross-browser

我已经阅读了一些关于此的内容,但我似乎找不到任何关于不同浏览器如何处理事物的可靠信息.

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 元素可以被聚焦(并且在通过表单切换"时获得焦点)而 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.

在 这篇很棒的文章 或 w3c 的定义.引用重要部分:

Read more about this in this great article or the definition by w3c. To quote the important part:

主要区别

禁用属性

  • 禁用的表单元素的值不会传递给处理器方法.W3C 称这是一个成功的元素.(这类似于形成未选中的复选框.)
  • 某些浏览器可能会覆盖或为禁用的表单元素提供默认样式.(灰色或浮雕文本) Internet Explorer5.5 对此特别讨厌.
  • 禁用的表单元素不会获得焦点.
  • 在标签导航中跳过禁用的表单元素.

只读属性

  • 并非所有表单元素都有只读属性.最值得注意的是, <SELECT><OPTION><BUTTON> 元素没有只读属性(尽管它们都有禁用的属性)
  • 浏览器不提供表单元素为只读的默认覆盖视觉反馈.(这可能是个问题……见下文.)
  • 带有只读属性集的表单元素将被传递给表单处理器.
  • 只读表单元素可以接收焦点
  • 只读表单元素包含在选项卡式导航中.
  • 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.

相关文章