gpt4 book ai didi

javascript - 如何在输入类型日期中设置占位符 [React]

转载 作者:行者123 更新时间:2023-12-05 00:33:07 25 4
gpt4 key购买 nike

我想知道如何在输入日期中设置占位符。
这是我的代码

<input type="text" onChange={(e) => { setbirth(moment(e.target.value).format('YYYYMMDD')) }} placeholder="생년월일" onFocus="(this.type = 'date')" onBlur="(this.type='text')" />
我已经查看了这个问题,但是使用了这段代码
引发错误。
onfocus="(this.type='date')" onblur="(this.type='text')"


Warning: Expected `onFocus` listener to be a function, instead got a value of `string` type.
Warning: Expected `onBlur` listener to be a function, instead got a value of `string` type.
有什么方法可以无误地更改它吗?

最佳答案

import React , { useRef } from "react";

const App= () => {
const ref = useRef();
return (
<div>
<input
type="date"
ref={ref}
onChange={(e) => console.log(e.target.value)}
onFocus={() => (ref.current.type = "date")}
onBlur={() => (ref.current.type = "date")}
/>
</div>
);
}
export default App

关于javascript - 如何在输入类型日期中设置占位符 [React],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68480474/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com