【问题标题】:Restrict date input for specific intervale of time限制特定时间间隔的日期输入
【发布时间】:2022-10-14 23:14:29
【问题描述】:

我正在构建一个 React 应用程序,但它与 React 没有任何关系,我想让用户在接下来的两周内只选择一天,并带有 input[type="date"] 标签。

我不知道如何将 input 限制在特定的时间段内(例如接下来的 14 天)。

请帮我!

【问题讨论】:

    标签: html date input tags restriction


    【解决方案1】:

    我正在构建一个 React 应用程序,但它与 React 无关

    这是什么意思?你创建了一个 React 项目但没有使用 React?

    有几个选项可以做到这一点react-datepickermoment.js 是我最喜欢创建日期选择器和创建自定义日期约束的方法。

    Here 是将原始输入限制在两周后的堆栈闪电战。

    let twoWeeks = new Date(Date.now() + 12096e5)
    .toISOString()
    .split('T')[0]
    .toLocaleString([], {
      year: 'numeric',
      month: 'numeric',
      day: 'numeric',
    });
    
    <input type="date" max={twoWeeks} />
    

    【讨论】:

      猜你喜欢
      • 2015-10-03
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多