英文:
defaultValue for input type 'date' is not working in Nextjs
问题
我正在使用Next.js,我想使用HTML标签,输入类型为'date'。我还想设置一个defaultValue,我做了类似这样的事情,但它不起作用:
const [dDate, setdDate] = useState('17/11/2022');
const ReactComponent = () => {
return (
<input
type="date"
className="border-2 py-1 px-2 rounded-md"
onChange={(text) => handleDepositeDate(text.target.value, index)}
defaultValue={dDate}
/>
);
};
它不显示在屏幕上。我还尝试使用value
而不是defaultValue
,仍然不起作用。我还尝试了应用程序中的其他日期输入,defaultValue也不起作用。
英文:
I am using Nextjs and I would like to use the html tag, input type of 'date'. I also would like to set a defaultValue and I did something like this and it is not working:
const [dDate, setdDate] = useState('17/11/2022');
const ReactComponent = ()=>{
return(
<input type="date" className=" border-2 py-1 px-2 rounded-md"
onChange={(text)=>handleDepositeDate(text.target.value, index)} defaultValue={dDate}
/>
)
};
It does not display on the screen. I also tried using value
instead of defaultValue
, still didn't work. I also tried other date input on the application and defaultValue didn't work.
答案1
得分: 1
尝试使用不同的日期格式与值属性,如下所示:
<input type="date" value="2022-11-17"/>
英文:
Try using a different date format with the value attribute, like so:
<input type="date" value="2022-11-17"/>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论