如何在onCahnge事件中获得价值?

Triyugi Narayan玛尼

我正在使用react-input-calendar我想获取日期onChange事件的值,然后将其传递到新页面。我怎样才能做到这一点?

代码如下:

constructor() {
    super();
    this.state = {value: new Date(),inputdate:''};
    this.handleChange = this.handleChange.bind(this);
}

handleChange(newDate, event) { 
    console.log(newDate);
    this.setState({inputdate:newDate});
}

<Calendar format='dddd DD MMM' closeOnSelect={true} date={this.state.value}
ref="inputdate" inputName="inputdate" computableFormat='MM-DD-YYYY' onChange=
{this.handleChange.bind(this,"inputdate")} />

我如何获得价值handleChange

马丁·道森(Martin Dawson)

props.onChange,功能

默认值:null

设置一个在所选日期发生更改时将触发的功能。它将以props.computableFormat格式返回日期。

根据文档,它应该像这样可用:

constructor(props) {
    super(props);

    this.handleChange = this.handleChange.bind(this);
}
handleChange(newDate, event) {
    //newDate should be passed here
    console.log(newDate);
}

<Calendar format='dddd DD MMM' closeOnSelect={true} date={this.state.value0}
ref="inputdate" inputName="inputdate" computableFormat='MM-DD-YYYY' onChange=
{this.handleChange} />

检查src代码以及传入的对象的属性。看起来该库调用了onChange属性并传入newDate

if (this.props.onChange) {
    this.props.onChange(computableDate)
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章