disabled="disabled" 和有什么不一样?和只读=“只读"用于 HTML 表单输入字段? [英] What's the difference between disabled="disabled" and readonly="readonly" for HTML form input fields?

查看:34
本文介绍了disabled="disabled" 和有什么不一样?和只读=“只读"用于 HTML 表单输入字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

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

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

主要区别

禁用属性

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

只读属性

  • 并非所有表单元素都具有只读属性.最值得注意的是,
发送“验证码”获取 | 15天全站免登陆