How to set a default month in an input element?
问题 Say I have an input element like this: <input type="month"> How can I set the default value of this input element to the current month? 回答1: You may use some javascript: const monthControl = document.querySelector('input[type="month"]'); const date= new Date() const month=("0" + (date.getMonth() + 1)).slice(-2) const year=date.getFullYear() monthControl.value = `${year}-${month}`; <input type="month"> 回答2: You have to construct new Date and query your input, then do something like: let date =