Input Color autofocus Attribute

Definition and usage

autofocus Attribute setting or returning whether the color selector should automatically get focus when the page is loaded.

This property reflects the HTML autofocus attribute.

See also:

HTML Reference Manual:HTML <input> autofocus 属性

Example

Check if the color selector will automatically get focus when the page is loaded:

var x = document.getElementById("myColor").autofocus;

Try it yourself

Syntax

Return the autofocus attribute:

colorObject.autofocus

Set the autofocus attribute:

colorObject.autofocus = true|false

Attribute value

Value Description
true|false

Specifies whether the color selector should get focus when the page is loaded.

  • true - The color selector gets focus
  • false - Default. The color selector does not get focus

Technical details

Return value: Boolean value, if the color selector automatically gets focus when the page is loaded, it returns true,否则返回 false

浏览器支持

表中的数字注明了首个完全支持该属性的浏览器版本。

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
支持 10.0 支持 支持 支持

注释:<input type="color"> 元素在 Internet Explorer 和 Safari 中不显示任何颜色选择器。