Safari 中的 HTML5 日期字段和占位符文本
我遇到了一个问题,但我不确定是否是我做错了什么,或者是否尚不支持此功能。
基本上我有以下几行代码:
<input type="text" name="lastname" id="lastname" value="" placeholder="Last name" />
<input type="date" name="dob" id="dob" value="" placeholder="Date of birth" />
我已经在桌面版 Safari 上测试了这一点,一切都很好,但是当我在 iPad 上测试它时,第二个输入不显示占位符文本。有谁知道 iPad 上的 type="date" 是否支持占位符文本?
干杯 缺口
I've got an issue, but I'm not sure if it's something I'm doing wrong, or if this feature just isn't supported yet.
Basically I have the following lines of code:
<input type="text" name="lastname" id="lastname" value="" placeholder="Last name" />
<input type="date" name="dob" id="dob" value="" placeholder="Date of birth" />
I've tested this on the desktop version of Safari and all good, but when I test it on the iPad, the second input doesn't show the placeholder text. Does anyone know if placeholder text is supported on type="date" on the iPad?
Cheers
Nick
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
iPad 正在做正确的事情。
占位符
属性date
类型的input
元素不支持。它可能适用于桌面版 Safari,因为它不支持date
类型,因此该属性被忽略,您只剩下一个纯文本字段。您可以检查 DOM 检查器。The iPad is doing the correct thing. The
placeholder
attribute isn't supported oninput
elements on typedate
. It's probably working on desktop Safari because that doesn't support thedate
type, so that attribute is being ignored and you're left with a plain text field. You could check in the DOM inspector.这里有一点小技巧...
最初将该字段设置为文本字段。当用户聚焦于该字段时,将字段类型切换为日期并重新聚焦。
在ios6中测试
HTML
JS
Slight hack bit here goes...
Initially have the field as a text field. When the user focuses on the field switch the fields type to date and re-focus.
tested in ios6
HTML
JS
iOS Safari 的 CSS:
然后在日期输入上使用占位符:
CSS for iOS Safari:
Then use placeholder on date input:
使用 sidarcy 的解:
Using the solution of sidarcy:
将其添加到标题中
add this to header