从html5 datepicker中禁用某些日期 [英] Disable certain dates from html5 datepicker

查看:371
本文介绍了从html5 datepicker中禁用某些日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在使用

时禁用日期我想要禁用一个方案的当前日期以及其他方案的未来日期。
如何禁用日期?

Is it possible to disable dates when I use I want to disable current date for one scenario and future dates for other scenario. How should I disable the dates?

推荐答案

您可以添加 min max 属性到输入类型=日期 。日期必须为ISO格式(yyyy-mm-dd)。许多移动浏览器和当前版本的Chrome都支持此功能,尽管用户可以手动输入无效的日期,而不使用datepicker。

You can add a min or max attribute to the input type=date. The date must be in ISO format (yyyy-mm-dd). This is supported in many mobile browsers and current versions of Chrome, although users can manually enter an invalid date without using the datepicker.

<input name="somedate" type="date" min="2013-12-25">

min max 属性必须为完整日期;没有办法指定今天或 +0 。为此,您需要使用JavaScript或服务器端语言:

The min and max attributes must be a full date; there's no way to specify "today" or "+0". To do that, you'll need to use JavaScript or a server-side language:

var today = new Date().toISOString().split('T')[0];
document.getElementsByName("somedate")[0].setAttribute('min', today);

http://jsfiddle.net/mblase75/kz7d2/

只有今天才能执行,而允许过去或将来的日期,不是选项与这里。但是,如果您的意思是希望明天成为 min 日期(今天和过去的所有日期),请参见这个问题今天今天增加。

Ruling out only today, while allowing past or future dates, is not an option with here. However, if you meant you want tomorrow to be the min date (blanking out today and all past dates), see this question to increment today by one day.

所有涉及HTML表单的其他情况,您应该总是验证现场服务器端,而不管您如何约束客户端。

As in all other cases involving HTML forms, you should always validate the field server-side regardless of how you constrain it client-side.

这篇关于从html5 datepicker中禁用某些日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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