【发布时间】:2017-02-18 15:35:03
【问题描述】:
我有以下代码
case 'date':
if (Modernizr.touchevents && Modernizr.inputtypes && Modernizr.inputtypes.date) {
element = (
<input
type='date'
id={this.props.id}
name={this.props.name}
onChange={arg => this.changeValue(moment(arg && arg.currentTarget ? arg.currentTarget.value : arg))}
onBlur={arg => this.blurValue(moment(arg && arg.currentTarget ? arg.currentTarget.value : arg))}
value={this.getValue() ? moment(this.getValue()).format('YYYY-MM-DD') : moment(this.props.minDate).format('YYYY-MM-DD')}
tabIndex={this.props.tabIndex}
min={this.props.minDate || null}
max={this.props.maxDate || null}
/>
);
} else {
element = (
<DatePicker
{...this.props}
name={this.props.name}
onChange={this.changeValue}
selected={this.getValue() || this.props.selected}
startDate={this.props.startDate || null}
endDate={this.props.endDate || null}
minDate={this.props.minDate || null}
tabIndex={this.props.tabIndex}
placeholderText={this.props.placeholder}
ref={this.props.elRef}
disabled={this.props.disabled}
showYearDropdown={this.props.showYearDropdown}
locale={this.lang}
/>
);
}
break;
}
这会在我的登录页面上加载一个反应日期选择器。
由于它已被大量使用,我想通过在页面加载时自动打开日期选择器来使其更加用户友好。 我一直在搜索,但我没有找到一种简单、直接的方法。
我找到了这个主题 (https://github.com/Hacker0x01/react-datepicker/issues/276) 但由于我对 Javascript 和 React 有点陌生,我需要更多关于如何在我的代码中实现此代码的解释,所以如果有人能解释一下,那就太好了我应该把我的代码放在哪里来实现这个功能
非常感谢大家!
【问题讨论】:
标签: javascript reactjs datepicker