Textarea autofocus 属性

定义和用法

autofocus 属性设置或返回文本区域是否应在页面加载时自动获得焦点。

此属性反映 HTML autofocus 属性。

另请参阅:

HTML 参考手册:HTML <input> autofocus 属性

实例

查明文本区域是否在页面加载时自动获得焦点:

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

亲自试一试

语法

返回 autofocus 属性:

textareaObject.autofocus

设置 autofocus 属性:

textareaObject.autofocus = true|false

属性值

描述
true|false

Specify whether the textarea should get focus when the page loads.

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

Technical Details

Return Value: Boolean value, if the textarea automatically gets focus when the page loads, it returns true; otherwise return false.

Browser Support

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Support 10.0 Support Support Support