Html 是自动对焦=“自动对焦”还是自动对焦?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4445765/
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 05:43:06  来源:igfitidea点击:

is it autofocus="autofocus" or autofocus?

htmlautofocus

提问by Darryl Hein

I seem to recall most (maybe all) attributes in previously versions of HTML (before HTML5) required attributes to have values, like readonly="readonly".

我似乎记得以前版本的 HTML(HTML5 之前)中的大多数(也许所有)属性都需要具有值的属性,例如readonly="readonly".

Is this true for HTML5 and the autofocusattribute?

这对 HTML5 和autofocus属性来说是真的吗?

回答by Tim

In HTML, you use boolean attributes with or without values as you like. A boolean, for W3C, like autofocus can be written like that autofocusor autofocus="autofocus"or also autofocus="".

在 HTML 中,您可以根据需要使用带或不带值的布尔属性。一个布尔值,对于 W3C,像 autofocus 可以这样写,autofocus或者autofocus="autofocus"或者也autofocus=""

If you don't want autofocus just don't write it.

如果你不想自动对焦,就不要写它。

I think you are confused because XHTML requires values for all attributes: attributes="values".

我认为您很困惑,因为 XHTML 需要所有属性的值:attributes="values".

Here is some information about boolean attribute use in HTML: http://www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attribute

以下是有关 HTML 中布尔属性使用的一些信息:http: //www.whatwg.org/specs/web-apps/current-work/multipage/common-microsyntaxes.html#boolean-attribute

回答by Pekka

No, it's enough to specify the attribute itself. It was that way also in HTML 4.

,指定属性本身就足够了。在HTML 4 中也是如此。

A number of attributes are boolean attributes. The presence of a boolean attribute on an element represents the true value, and the absence of the attribute represents the false value.

If the attribute is present, its value must either be the empty string or a value that is an ASCII case-insensitive match for the attribute's canonical name, with no leading or trailing whitespace.

许多属性是布尔属性。元素上布尔属性的存在表示真值,不存在该属性表示假值。

如果该属性存在,则其值必须是空字符串,或者是与该属性的规范名称不区分大小写的 ASCII 匹配值,且没有前导或尾随空格。

Example:

例子:

<label><input type=checkbox checked name=cheese disabled> Cheese</label>