javascript - 如何在输入类型日期中设置占位符 [React]
问题描述
我想知道如何在输入日期中设置占位符。
这是我的代码
<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
推荐阅读
- typescript - 对象传播不适用于 TypeScript 中的泛型?为什么不?
- firebase - 如何删除自动 Google Cloud Firestore 索引?
- r - 如果它们与另一个数据帧匹配,则从 r 中的数据帧中提取行
- java - MiniMax 算法在增加深度后不智能
- angular - Angular 5 + Angular Material Select + Reactive Forms == 不显示初始选项
- r - 对列因子使用 RStudio 的自动完成功能而不明确定义它们?
- android - 如何在视图中绑定来自 JSON 图像路径的图像?
- php - 了解询问 - 在 foreach 循环中将索引组合在一起
- amazon-web-services - Athena - 创建动态 JSON 列
- java - 在线Web逻辑服务器上部署的War文件中的Jsp / Html页面发生变化而无需重新部署?