简体   繁体   English

如何禁用html5 datepicker上的仅选定日期?

[英]How can I disable only selected dates on html5 datepicker?

How can I disable few dates (Ex: one week) on a HTML datepicker? 如何禁用HTML日期选择器上的几个日期(例如:一周)? I have an input item like this 我有这样的输入项

<input type="date" id="date01" name="date01" max="2019-12-30">

I know I can use min and max values to limit available time period, but in here, I want to block out some days in the middle. 我知道我可以使用最小值和最大值来限制可用时间段,但是在这里,我想在中间屏蔽几天。 can I do that with plain html date picker? 我可以用纯HTML日期选择器吗? if so, how? 如果是这样,怎么办?

You can't: the HTML5 date input only accepts a lower and upper bound to indicate the allowed date range: you cannot specifically select certain dates that are disabled/non-selectable to the user. 您不能:HTML5的date输入只接受一个上限和下限,表示允许的日期范围:您不能明确选择特定日期已禁用/不可选择给用户。

There are two solutions to your approach: 您的方法有两种解决方案:

  • Use a combination of client- and server-side validation to let the user know that certain dates are not allowed. 结合使用客户端验证和服务器端验证,可以使用户知道不允许使用某些日期。 This comes at the cost that the user does not know which dates are not allowed when the native date picker is shown in the browser. 这样做的代价是,当在浏览器中显示本机日期选择器时,用户不知道不允许哪个日期。
  • Alternatively, you can use a third-party library that allows disabling of specific dates. 或者,您可以使用允许禁用特定日期的第三方库。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM