1. 首页
  2. css

CSS数字邮政编码的HTML

我刚刚在Twitter上无意中听到了这个讨论,由Dave发起。
Me(编写表单):<input>Tiny Devil(出现在肩膀上):Yaaas!我喜欢乐观主义,加油!
我:等等,你为什么在这里?这会对我造成伤害吗?你知道什么我不知道?
-Dave SPOOPert(@davatron5000)2018年10月9日
似乎邮政编码只是数字,对吧?所以…

The advantage there being able to take advantage of free validation from the browser, and triggering a more helpful number-based keyboard on mobile devices.
But Zach pointed out that> is problematic for zip codes because zip codes can have leading zeros (e.g. a Boston zip code might be 02119). Filament group also has a little lib for fixing this.
This is the perfect job for inputmode,正如Jeremy所建议的:

But the support is pretty bad at the time of this writing.
A couple of people mentioned trying to hijack> for it, but that has its own downsides, like rejecting properly formatted 9-digit zip codes.
So, zip codes, while they look like numbers, are probably best treated as strings. Another option here is to leave it as a text输入,但强制使用带有pattern的数字,如Pamela Fox文档:
<input>
正如许多人在评论中指出的那样,值得注意的是,邮政编码的数字模式最适合美国,因为许多其他国家的邮政编码都包含数字和字母

CSS数字邮政编码的HTML 为WP2原创文章,链接:https://www.wp2.cn/css/css%e6%95%b0%e5%ad%97%e9%82%ae%e6%94%bf%e7%bc%96%e7%a0%81%e7%9a%84html/