Input Text placeholder 属性
定义和用法
placeholder
属性设置或返回文本字段的 placeholder 属性的值。
HTML placeholder 属性规定描述对文本字段的预期值的简短提示(例如,示例值或对预期格式的简短描述)。
在用户输入值之前,短提示会显示在文本字段中。
另请参阅:
HTML 参考手册:Sifat placeholder <input> HTML
实例
例子 1
更改文本字段的占位符文本:
document.getElementById("myText").placeholder = "Type name here..";
例子 2
获取文本字段的占位符文本:
var x = document.getElementById("myText").placeholder;
语法
返回 placeholder 属性:
textObject.placeholder
设置 placeholder 属性:
textObject.placeholder = text
Attribute Value
Value | Description |
---|---|
text | Specifies a brief hint (word or phrase) describing the expected value of the text field. |
Technical Details
Return value: | String value, indicating a brief hint of the expected value of the text field. |
---|
Browser Support
The numbers in the table indicate the first browser version that fully supports this property.
Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|
Chrome | Edge | Firefox | Safari | Opera |
Support | 10.0 | Support | Support | Support |