问题描述
邮政地址的 autofill
属性具有 4 different "administrative levels"。该文档为美国、英国、中国和日本提供了一些示例。我想知道德国地址中的城市是否有一些规范(或所有国家/地区如何构建其行政级别的表格)。对于德国,使用 address-level1
和 address-level2
对城市都有意义:
-
address-level1
因为通常我们不会在地址中包含县(联邦),所以使用“最高”级别是有道理的,模仿英国地址的指定方式。 -
address-level2
因为如果你想非常具体,它是地址的第 2 级,第 1 级是县。
有任何官方参考或数据可以备份吗?
解决方法
我想说,address-level2
是德国地址所需要的。
第二个行政级别,在具有两个或多个行政级别的地址中; 在具有两个行政级别的国家/地区,这通常是找到相关街道地址的城市、城镇、村庄或其他地点
这是我使用的:
<form>
<input type="text" autocomplete="address-line1" placeholder="Straße und Hausnummer"/>
<input type="text" autocomplete="postal-code" placeholder="PLZ"/>
<input type="text" autocomplete="address-level2" placeholder="Stadt"/>
</form>
如果您想拆分街道名称和门牌号码,您需要使用一种解决方法:
<form>
<input type="text" autocomplete="address-line1" placeholder="Straße"/>
<!-- "address-level4" is used as a workaround,because Chrome ignores `autocomplete="off"` -->
<input type="text" autocomplete="address-level4" placeholder="Hausnummer"/>
<input type="text" autocomplete="postal-code" placeholder="PLZ"/>
<input type="text" autocomplete="address-level2" placeholder="Stadt"/>
</form>