38 lines
901 B
Markdown
38 lines
901 B
Markdown
|
---
|
||
|
title: Placeholder Attribute
|
||
|
localeTitle: 占位符属性
|
||
|
---
|
||
|
## 占位符属性| HTML5
|
||
|
|
||
|
指定描述`<input>`或`<textarea>`表单控件的预期值的简短提示。
|
||
|
|
||
|
占位符属性不得包含回车符或换行符。
|
||
|
|
||
|
注意:不要使用占位符属性而不是<label>元素,它们的用途是不同的。 <label>属性描述了表单元素的作用(即它指示了预期的信息类型),占位符属性是关于内容应该采用的格式的提示。
|
||
|
|
||
|
### 例
|
||
|
|
||
|
输入示例
|
||
|
|
||
|
```html
|
||
|
|
||
|
<form>
|
||
|
<input type="text" name="fname" placeholder="First Name">
|
||
|
<input type="text" name="lname" placeholder="Last Name">
|
||
|
</form>
|
||
|
```
|
||
|
|
||
|
Textarea例子
|
||
|
|
||
|
```html
|
||
|
|
||
|
<textarea placeholder="Describe yourself here..."></textarea>
|
||
|
```
|
||
|
|
||
|
### 兼容性
|
||
|
|
||
|
这是一个HTML5属性。
|
||
|
|
||
|
#### 更多信息:
|
||
|
|
||
|
w3schools.com上的[HTML占位符属性](https://www.w3schools.com/tags/att_placeholder.asp)
|