“defaultValue” 对于输入类型 ‘date’ 在 Next.js 中不起作用。

huangapple go评论56阅读模式
英文:

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(&#39;17/11/2022&#39;);


const ReactComponent = ()=&gt;{
  
    return(
       
          &lt;input type=&quot;date&quot; className=&quot; border-2 py-1 px-2 rounded-md&quot; 
         onChange={(text)=&gt;handleDepositeDate(text.target.value, index)} defaultValue={dDate} 
      /&gt;
     )

 };

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:

&lt;input type=&quot;date&quot; value=&quot;2022-11-17&quot;/&gt;

huangapple
  • 本文由 发表于 2023年6月1日 23:26:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383483.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定