|
1 |
| -autocomplete.md |
| 1 | +HTML autocomplete 属性 |
2 | 2 | ===
|
3 | 3 |
|
4 |
| -欢迎您编辑 <a target="__blank" href="https://github.com/jaywcjlove/html-tutorial/blob/main/docs/attribute/autocomplete.md">docs/attribute/autocomplete.md</a> 文件,共建 HTML Tutorial 文档。 |
| 4 | +## 定义和用法 |
| 5 | + |
| 6 | +`autocomplete` 属性指定表单或输入字段是否应该打开或关闭自动完成功能。 |
| 7 | + |
| 8 | +自动完成允许浏览器预测值。 当用户开始输入字段时,浏览器应根据之前输入的值显示填充字段的选项。 |
| 9 | + |
| 10 | +**提示:** 可以为表单设置“开启”自动完成功能,为特定输入字段设置“关闭”功能,反之亦然。 |
| 11 | + |
| 12 | +**注意:** `autocomplete` 属性适用于以下 [`<input>`](../tags/input.md) 类型:[文本](../tags/input_type_text.md)、[搜索](../tags/input_type_search.md)、[url](../tags/input_type_url.md)、[电话](../tags/input_type_tel.md)、[电子邮件](../tags/input_type_email.md)、[密码](../tags/input_type_password.md)、[日期选择器](../tags/input_type_date.md)、[范围](../tags/input_type_range.md)和[颜色](../tags/input_type_color.md)。 |
| 13 | + |
| 14 | +## 适用于 |
| 15 | + |
| 16 | +`autocomplete` 属性可用于以下元素: |
| 17 | + |
| 18 | +| 标签 Element | 属性 Attribute | |
| 19 | +| ----- | ----- | |
| 20 | +| [\<form>](../tags/form.md) | [autocomplete](../tags/form_autocomplete.md) | |
| 21 | +| [\<input>](../tags/input.md) | [autocomplete](../tags/input_autocomplete.md) | |
| 22 | + |
| 23 | +## 示例 |
| 24 | + |
| 25 | +### Form 示例 |
| 26 | + |
| 27 | +具有自动完成功能的表单: |
| 28 | + |
| 29 | +```html idoc:preview:iframe |
| 30 | +<form action="/action\_page.php" method="get" autocomplete="on"> |
| 31 | + First name:<input type="text" name="fname"><br> |
| 32 | + E-mail: <input type="email" name="email"><br> |
| 33 | + <input type="submit"> |
| 34 | +</form> |
| 35 | +``` |
| 36 | + |
| 37 | +### Input 示例 |
| 38 | + |
| 39 | +具有自动完成功能的 HTML 表单(一个输入字段关闭): |
| 40 | + |
| 41 | +```html idoc:preview:iframe |
| 42 | +<form action="/action_page.php" autocomplete="on"> |
| 43 | + First name:<input type="text" name="fname"><br> |
| 44 | + Last name: <input type="text" name="lname"><br> |
| 45 | + E-mail: <input type="email" name="email" autocomplete="off"><br> |
| 46 | + <input type="submit"> |
| 47 | +</form> |
| 48 | +``` |
| 49 | + |
| 50 | +## 浏览器支持 |
| 51 | + |
| 52 | +`autocomplete` 属性对每个元素都有以下浏览器支持: |
| 53 | + |
| 54 | +| 标签 Element | ![chrome][1] | ![edge][2] | ![firefox][3] | ![safari][4] | ![opera][5] | |
| 55 | +| ------- | --- | --- | --- | --- | --- | |
| 56 | +| [form](../tags/form.md) | Yes | Yes | 4.0 | 5.2 | 15.0 | |
| 57 | +| [input](../tags/input.md) | 17.0 | 5.0 | 4.0 | 5.2 | 9.6 | |
| 58 | + |
| 59 | +[1]: ../assets/chrome.svg |
| 60 | +[2]: ../assets/edge.svg |
| 61 | +[3]: ../assets/firefox.svg |
| 62 | +[4]: ../assets/safari.svg |
| 63 | +[5]: ../assets/opera.svg |
0 commit comments