我想知道是否有某种特殊的标记,以启用Chrome自动填充功能的特定形式。我只发现了关于如何禁用它的问题,但我想知道我是否可以向html代码添加某种标记,以便告诉浏览器“这是地址的输入”或“这是邮政编码字段”,以正确地填充它(假设用户激活了此功能)。
当前回答
您需要适当地命名元素,以便浏览器自动填充它们。
下面是IETF的规范:
http://www.ietf.org/rfc/rfc3106.txt1
其他回答
我只是摆弄了一下规范,得到了一个很好的工作示例——包括更多的字段。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<form autocomplete="on" method="POST">
<fieldset>
<legend>Ship the blue gift to...</legend>
<p>
<label> Firstname:
<input name="fname" autocomplete="section-blue shipping given-name" type="text" required>
</label>
</p>
<p>
<label> Lastname:
<input name="fname" autocomplete="section-blue shipping family-name" type="text" required>
</label>
</p>
<p>
<label> Address: <input name=ba
autocomplete="section-blue shipping street-address">
</label>
</p>
<p>
<label> City: <input name=bc
autocomplete="section-blue shipping address-level2">
</label>
</p>
<p>
<label> Postal Code: <input name=bp
autocomplete="section-blue shipping postal-code">
</label>
</p>
</fieldset>
<fieldset>
<legend>Ship the red gift to...</legend>
<p>
<label> Firstname:
<input name="fname" autocomplete="section-red shipping given-name" type="text" required>
</label>
</p>
<p>
<label> Lastname:
<input name="fname" autocomplete="section-red shipping family-name" type="text" required>
</label>
</p>
<p>
<label> Address: <input name=ra
autocomplete="section-red shipping street-address">
</label>
</p>
<p>
<label> City: <input name=bc
autocomplete="section-red shipping address-level2">
</label>
</p>
<p>
<label> Postal Code: <input name=rp
autocomplete="section-red shipping postal-code">
</label>
</p>
</fieldset>
<fieldset>
<legend>payment address</legend>
<p>
<label> Firstname:
<input name="fname" autocomplete="billing given-name" type="text" required>
</label>
</p>
<p>
<label> Lastname:
<input name="fname" autocomplete="billing family-name" type="text" required>
</label>
</p>
<p>
<label> Address: <input name=ra
autocomplete="billing street-address">
</label>
</p>
<p>
<label> City: <input name=bc
autocomplete="billing address-level2">
</label>
</p>
<p>
<label> Postal Code: <input name=rp
autocomplete="billing postal-code">
</label>
</p>
</fieldset>
<input type="submit" />
</form>
</body>
</html>
JSBIN
它包含2个单独的地址区域和不同的地址类型。 在iOS 8.1.0上也进行了测试,似乎它总是一次填充所有字段,而桌面chrome浏览器会自动按地址填充地址。
这是真正的答案:
http://jsfiddle.net/68LsL1sq/1/ <label for="name">Nom</label> 这不是:http://jsfiddle.net/68LsL1sq/2/ <label for="name">否</label>
唯一的区别在于标签本身。“Nom”来自葡萄牙语中的“Name”或“Nome”。
这就是你所需要的:
表单包装器; A <label for="id_of_field">Name</label> An <input id="id_of_field"></input>
仅此而已。
谷歌现在为此提供文档:
帮助用户更快地自动填充| Web |谷歌开发人员
and
创建惊人的表单:使用元数据来启用自动完成| Web |谷歌开发人员
这个问题很老了,但我有一个最新的答案!
这里有一个WHATWG文档的链接,用于启用自动补全。
谷歌写了一个非常好的指南,用于开发适合移动设备的web应用程序。他们有一个章节介绍如何为表单上的输入命名,以便轻松使用自动填充。尽管它是为移动设备编写的,但这适用于桌面和移动设备!
如何在HTML表单上启用自动完成
以下是关于如何启用自动完成的一些关键点:
Use a <label> for all your <input> fields Add a autocomplete attribute to your <input> tags and fill it in using this guide. Name your name and autocomplete attributes correctly for all <input> tags Example: <label for="frmNameA">Name</label> <input type="text" name="name" id="frmNameA" placeholder="Full name" required autocomplete="name"> <label for="frmEmailA">Email</label> <input type="email" name="email" id="frmEmailA" placeholder="name@example.com" required autocomplete="email"> <!-- note that "emailC" will not be autocompleted --> <label for="frmEmailC">Confirm Email</label> <input type="email" name="emailC" id="frmEmailC" placeholder="name@example.com" required autocomplete="email"> <label for="frmPhoneNumA">Phone</label> <input type="tel" name="phone" id="frmPhoneNumA" placeholder="+1-555-555-1212" required autocomplete="tel">
如何命名你的<input>标签
为了触发自动补全,请确保您正确命名<input>标记中的名称和自动补全属性。这将自动允许在表单上自动完成。确保还有一个<label>!这些信息也可以在这里找到。
以下是如何命名你的输入:
Name Use any of these for name: name fname mname lname Use any of these for autocomplete: name (for full name) given-name (for first name) additional-name (for middle name) family-name (for last name) Example: <input type="text" name="fname" autocomplete="given-name"> Email Use any of these for name: email Use any of these for autocomplete: email Example: <input type="text" name="email" autocomplete="email"> Address Use any of these for name: address city region province state zip zip2 postal country Use any of these for autocomplete: For one address input: street-address For two address inputs: address-line1 address-line2 address-level1 (state or province) address-level2 (city) postal-code (zip code) country Phone Use any of these for name: phone mobile country-code area-code exchange suffix ext Use any of these for autocomplete: tel Credit Card Use any of these for name: ccname cardnumber cvc ccmonth ccyear exp-date card-type Use any of these for autocomplete: cc-name cc-number cc-csc cc-exp-month cc-exp-year cc-exp cc-type Usernames Use any of these for name: username Use any of these for autocomplete: username Passwords Use any of these for name: password Use any of these for autocomplete: current-password (for sign-in forms) new-password (for sign-up and password-change forms)
资源
当前WHATWG自动完成的HTML标准。 “创造惊人的形式”从谷歌。似乎每天都在更新。优秀的阅读。 2015年谷歌发布的“自动填充帮助用户更快结帐”。
您需要适当地命名元素,以便浏览器自动填充它们。
下面是IETF的规范:
http://www.ietf.org/rfc/rfc3106.txt1
推荐文章
- 使伸缩项目正确浮动
- 卸载Chrome开发工具
- 形式内联内的形式水平在twitter bootstrap?
- 自定义元素在HTML5中有效吗?
- 如何触发自动填充在谷歌Chrome?
- CSS变换,锯齿边缘在铬
- 创建圈div比使用图像更容易的方法?
- 为什么Chrome浏览器不正确地确定页面是在不同的语言,并提供翻译?
- 在网页上用鼠标模拟震颤(例如帕金森病)?
- Bootstrap抛出Uncaught错误:Bootstrap的JavaScript需要jQuery
- 如何改变文本区域的边框颜色:焦点
- 我如何设置背景颜色为文本的宽度,而不是整个元素的宽度,使用CSS?
- 如何删除和清除所有的本地存储数据
- 强制打开“另存为…”弹出打开文本链接点击PDF在HTML
- 如何修改标签文本?