Html disabled 属性的正确值是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6961526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:55:26  来源:igfitidea点击:

What is the correct value for the disabled attribute?

htmltextboxtextarea

提问by tskuzzy

What is the correct value for the disabledattribute for a textbox or textarea?

disabled文本框或文本区域的属性的正确值是多少?

I've seen the following used before:

我以前见过以下使用过:

<input type="text" disabled />
<input type="text" disabled="disabled" />
<input type="text" disabled="true" />

采纳答案by Erick Petrucelli

  • For XHTML, <input type="text" disabled="disabled" />is the valid markup.
  • For HTML5, <input type="text" disabled />is valid and used by W3C on their samples.
  • In fact, both ways works on all major browsers.
  • 对于 XHTML,<input type="text" disabled="disabled" />是有效的标记。
  • 对于 HTML5,<input type="text" disabled />有效并由 W3C 在其示例中使用。
  • 事实上,这两种方式都适用于所有主要浏览器。

回答by Edmond ME

I just tried all of these, and for IE11, the only thing that seems to work is disabled="true". Values of disabled or no value given didnt work. As a matter of fact, the jsp got an error that equal is required for all fields, so I had to specify disabled="true" for this to work.

我只是尝试了所有这些,对于 IE11,似乎唯一有效的是禁用 =“true”。禁用或没有给定值的值不起作用。事实上,jsp 得到一个错误,即所有字段都需要 equal,因此我必须指定 disabled="true" 才能使其工作。

回答by MadsHaupt

In HTML5, there is no correct value, all the major browsers do not really care what the attribute is, they are just checking if the attribute exists so the element is disabled.

在 HTML5 中,没有正确的值,所有主流浏览器并不真正关心属性是什么,它们只是检查属性是否存在,从而禁用元素。