Textarea placeholder attribute

Definition and Usage

placeholder Set or return the placeholder attribute value of the text area.

The HTML placeholder attribute specifies a brief hint describing the expected value of the text area (for example, a sample value or a brief description of the expected format).

The hint will be displayed in the empty text area and disappear when the field gains focus.

See also:

HTML Reference Manual:HTML <textarea> placeholder 属性

Example

Example 1

Change the placeholder text of the text area:

document.getElementById("myTextarea").placeholder = "Where do you live?";

Try it yourself

Example 2

Get the placeholder text of the text area:

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

Try it yourself

Syntax

Return placeholder attribute:

textareaObject.placeholder

Set placeholder attribute:

textareaObject.placeholder = text

属性值

描述
text 规定描述对文本区域预期值的简短提示(单词或短语)。

技术细节

返回值: 字符串值,表示描述对文本区域预期值的简短提示。

浏览器支持

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