Files
freeCodeCamp/guide/chinese/html/attributes/autofocus-attribute/index.md
2018-10-16 21:32:40 +05:30

35 lines
892 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Autofocus Attribute
localeTitle: 自动对焦属性
---
## 自动对焦属性| HTML5
**autofocus**属性是布尔属性。
如果存在,它指定元素应在页面加载时自动获得输入焦点。
文档中只有一个表单元素可以具有**自动聚焦**属性。它不能应用于`<input type="hidden">`
### 适用于
|元素|属性| | - | - | | `<button>` |自动对焦| | `<input>` |自动对焦| | `<select>` |自动对焦| | `<textarea>` |自动对焦|
### 例
```html
<form>
<input type="text" name="fname" autofocus>
<input type="text" name="lname">
</form>
```
### 兼容性
这是一个HTML5属性。
#### 更多信息:
w3schools.com上的[HTML自动对焦属性](https://www.w3schools.com/tags/att_autofocus.asp)
MDN Web文档上的[<input> autofocus属性](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input)