如何在我的 html5 日期输入上设置最大值,以便 iOS Safari 可以识别它? [英] how can I set a max value on my html5 date input so that it could be recognized by safari for iOS?

查看:26
本文介绍了如何在我的 html5 日期输入上设置最大值,以便 iOS Safari 可以识别它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我猜标题很清楚?

这是我输入的日期:

<input type="date" id="birthdate" name="birthdate" value="" max="1993-12-07" required/>

在 chrome 中,我无法使用字段的小箭头输入高于 1993-12-07 的日期(但如果我自己写日期,我可以).

In chrome, I cannot enter a date superior to 1993-12-07 using the little arrows of the field (but if I write the date myself I can).

在 iOS 的 safari 中,关注该领域只会带来一个不错的日期选择器.但是,此日期选择器不限于max"属性.那我该怎么做呢?当然,我有一个服务器端表单验证,但我也想在客户端进行验证.任何的想法?谢谢!

In safari for iOS, focusing that field just brings a nice datepicker. However, this datepicker is NOT limited to the "max" attribute. So how can I do that? Of course, I have a server-side form validation but I want to make it on client-side too. Any idea? Thanks!

推荐答案

Safari 尚不支持它.截至 2011 年 11 月,只有 Opera 和 chrome 支持它.无论如何这里是关于它的 w3spec http://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.max

Safari does not yet support it yet . Only Opera and chrome support it as of Nov 2011. Anyways here is the w3spec on it http://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.max

您可以在提交或更改时使用 js 验证.使用您选择的 js 验证框架

You can use js validation on submit or on change. Use a js validation framework of your choice

这里是纯 js 示例 http://www.roseindia.net/answers/viewqa/Ajax/4734-start-date-and-end-date-validation-in-javascript.html.使用您的最大日期而不是结束日期

Here is pure js example http://www.roseindia.net/answers/viewqa/Ajax/4734-start-date-and-end-date-validation-in-javascript.html. Use your max date instead of end date

对于 jquery 解决方案,请查看此 验证结束日期大于jQuery 的开始日期

For jquery solution look at this Validate that end date is greater than start date with jQuery

这篇关于如何在我的 html5 日期输入上设置最大值,以便 iOS Safari 可以识别它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆