这不是关于何时,而是关于如何我们可以在 Safari 浏览器中启用此功能。
我们来说说提交表单时会发生什么:
一些浏览器使用name 属性存储所有input 值。当遇到相同的 named input 元素时,它会自动完成这些字段。
有些浏览器只扫描autocomplete 属性以提供自动完成功能,
其他一些人也会扫描label 或name 之类的属性以查找input 元素。
现在,autocomplete 属性可以具有更大的值集,包括 cc-name(卡名)、cc-number、cc-exp、cc-csc(安全号码 - CVV)等(完整列表 here )
例如,我们可以对浏览器说,这是卡号字段,它应该尽可能提供autocomplete,并且它应该启用扫描信用卡功能:
<label>Credit card number:
<input type=text autocomplete="cc-number">
</label>
一般来说:
<input type="text" autocomplete="[section-](optional) [shipping|billing](optional)
[home|work|mobile|fax|pager](optional) [autofill field name]">
更详细的例子:
<input type="text" name="foo" id="foo" autocomplete="section-red shipping mobile tel">
每个自动完成值都是这样的:
section-red : wrapping as a section. (named red)
shipping : shopping/billing
mobile : home|work|mobile|fax|pager (For telephone)
tel : [Tokens][2]
当我们像这个浏览器一样编写代码时,就知道应该在该字段中填充什么样的值。
但像 safari 这样的浏览器需要 name 或 id 或 label 值也应该设置正确。
目前支持 autocomplete、id 和 name 属性用于自动完成值。
Browse Ver OS ID Name Autocomplete
Chrome 50 OS X 10.11.4 No Yes Yes
Opera 35 OS X 10.11.4 No Yes Yes
Firefox 46 OS X 10.11.4 Yes Yes No
Edge 25 Windows 10 No Yes No
Safari 9.1 OS X 10.11.4 Partial Partial Partial
Safari 9 iOS 9.3.1 Partial Partial Partial
这里有更多的东西在起作用。我强烈推荐我推荐的这个blog。