【问题标题】:HTML5 - Datepicker disable past dates without jQueryHTML5 - Datepicker 在没有 jQuery 的情况下禁用过去的日期
【发布时间】:2019-04-30 17:06:09
【问题描述】:

我应该如何在仅使用 HTML 的日期选择器中禁用过去的日期?

示例:假设今天是 2000/12/21,这就是日期选择器的外观。

【问题讨论】:

    标签: php html datepicker


    【解决方案1】:

    HTML5 支持minmax 属性。

    试一试下面的例子,你就会明白它是如何工作的!

      Enter a date before 2000-12-21:
      <input type="date" name="example1" max="2000-12-20"><br>
    
      Enter a date after 2000-12-21:
      <input type="date" name="example2" min="2000-12-22"><br>

    只需使用 PHP 自动将日期选择器更新为当前日期:

    <input type="date" name="example3" min="<?= date('Y-m-d') ?>">
    

    注意: Internet Explorer 9(及更低版本)不支持此功能。

    【讨论】:

      猜你喜欢
      • 2021-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      相关资源
      最近更新 更多