Input Text placeholder Attribute

Definition and Usage

placeholder Sets or returns the value of the placeholder attribute of the text field.

The HTML placeholder attribute specifies a short hint that describes the expected value of the text field (for example, a sample value or a brief description of the expected format).

A short hint is displayed in the text field before the user enters a value.

See also:

HTML Reference Manual:HTML <input> placeholder অ্যাট্রিবিউট

Example

Example 1

Change the placeholder text of the text field:

document.getElementById("myText").placeholder = "Type name here..";

Try it yourself

Example 2

Get the placeholder text of the text field:

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

Try it yourself

Syntax

Return placeholder attribute:

textObject.placeholder

set placeholder attribute:

textObject.placeholder = text

属性值

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

技术细节

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

浏览器支持

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

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