无法在输入类型日期中设置日期



我知道,以前有人问过类似的问题,但我不理解答案/我觉得它不能解决我的问题。我不能在我的输入类型date中设置日期。

export default function NewNoteModal() {
return(
<div id = "newNoteModal">
{minimumSetDate()}
<div id = "newNote-header">
<h2>NoteKeeper</h2>
</div>
<form id = "newNote-content">
<label htmlFor = "noteName">Note Name:</label>
<input type="text" id = "noteName"></input>
<br></br>
{/* ---------------------- */}
<label htmlFor="checkB-important">Important:</label>
<input type="checkbox" name="important" value="important" id = "checkB-important"></input>
<br></br>
{/* ---------------------- */}
<label htmlFor="remindDate">Remind me on:</label>
<input type="date" name="remindDate" id = "remindDate"></input>
<br></br>
{/* ---------------------- */}
</form>
</div>
);
}
function minimumSetDate(){
let today = new Date();
let day = today.getDate(); // typeof = number
let month = ('0' + (today.getMonth()+1)).slice(-2); // typeof = number
let year = today.getFullYear(); // typeof = number
let currentDate = `${year}-${month}-${day}`; // typeof = string;
console.log(typeof(currentDate), currentDate);
document.getElementById("remindDate").value = currentDate;
}

控制台给出"TypeError: Cannot set property 'value' of null">

然而这在w3schools, works

document.getElementById("myDate").value = "2014-02-09";

let today = new Date();
let day = today.getDate(); // typeof = number
let month = ('0' + (today.getMonth()+1)).slice(-2) // typeof = number
let year = today.getFullYear(); // typeof = number
let currentDate = `${year}-${month}-${day}`; // typeof = string;
document.getElementById("remindDate").value = currentDate;
<input type="date" id="remindDate">

最新更新