我如何在我的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?

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

问题描述



这是我的日期输入:

 < input type =dateid =birthdatename =birthdatevalue =max =1993-12-07required /> 

在chrome中,我不能输入超过1993-12-07的日期,使用字段(但是如果我自己写日期,我可以)。



在iOS的safari中,专注于该字段只是带来了一个很好的日期戳。但是,此datepicker不限于max属性。那我该怎么办呢当然,我有一个服务器端的表单验证,但我也想在客户端。
任何想法?谢谢!

解决方案

Safari还没有支持。截至2011年11月,Opera和Chrome才支持它。无论如何,这里是w3spec。 http://www.w3.org/TR/html-markup/input.date.html#input.date.attrs.max



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



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



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


The title is pretty clear I guess?

Here's my date input :

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

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).

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 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

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

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

For jquery solution look at this end date greater than start date - jquery validation

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

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