(ReactJS)如何获取类型date的输入的输入值?((ReactJS) How do you get the input value of an input of type date?)

编程入门 行业动态 更新时间:2024-10-07 16:15:40
(ReactJS)如何获取类型date的输入的输入值?((ReactJS) How do you get the input value of an input of type date?)

我现在有

<input type="date" onChange={(input) => { _this.setState({startDate: input})}}/>

无论我一直在改变什么(onChange部分ref等etc),startDate显示为未定义,当我console.log我的状态。 我甚至改变了startDate:input startDate:input.value ,它仍然没有奏效。

我尝试过使用很多反应库,比如react-datepicker等等。到目前为止,他们还没有真正为我工作过(我们有很多CSS,并且由于这个问题,他们的CSS被搞砸了)。

I currently have

<input type="date" onChange={(input) => { _this.setState({startDate: input})}}/>

No matter what I've been changing around (the onChange part to ref etc etc), startDate shows up as undefined when I console.log my state. I've even changed startDate:input to startDate:input.value and it still hasn't worked.

I tried using many react libraries such as react-datepicker and etc. So far they haven't really been working out for me(We have a ton of CSS and their CSS is messed up due to that issue).

最满意答案

不知道这是什么。

我建议检查input事件的MDN参考 ,以了解它们是什么/如何拦截它们。

请参阅下面的工作示例。

<input type="date" onChange={(event) => this.setState({startDate: event.target.value})}/>

Not sure what _this is.

I'd recommend checking out the MDN reference on input events to get an idea of what they are / how to intercept them.

See below for a working example.

<input type="date" onChange={(event) => this.setState({startDate: event.target.value})}/>

更多推荐

本文发布于:2023-04-29 09:44:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1335586.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类型   ReactJS   date   type   input

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!