【问题标题】:How can I do to highlight three specific dates?如何突出显示三个特定日期?
【发布时间】:2020-11-28 17:01:28
【问题描述】:

我正在尝试使用 React.js 和 Datepicker 突出显示三个特定日期:“10-11-2020”、“22-11-2020”、“07-11-2020”,但我没有做到这一点.这是我的代码:

import React, {useState, Component} from "react";
import DatePicker from "react-datepicker";
import "react-datepicker/dist/react-datepicker.css";

const Datepicker = (props) => {
  const [startDate, setStartDate] = useState(new Date());
 
  return (
    <DatePicker
      className="custom-select"
      dateFormat="dd/MM/yyyy"
      selected={startDate}
      highlightDates={["10-11-2020","22-11-2020", "07-11-2020"]}
    />
  );
};

export default Datepicker;

我把我的代码放在这里:https://codesandbox.io/s/unruffled-wescoff-mfpgj?file=/src/App.js

你能帮帮我吗?

【问题讨论】:

    标签: javascript html css reactjs datepicker


    【解决方案1】:

    您必须将 javascript 日期对象数组传递给 highlightDates

    <DatePicker
        .....
        highlightDates={[new Date("2020-11-15"), new Date("2020-11-20")]} //This should be js date array
    />
    

    Updated demo

    【讨论】:

      猜你喜欢
      • 2021-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-11
      • 2019-12-26
      • 1970-01-01
      • 2015-05-01
      相关资源
      最近更新 更多