diff --git a/components/datepicker/demo/time.md b/components/datepicker/demo/time.md index fe9474087b..b525f9614b 100644 --- a/components/datepicker/demo/time.md +++ b/components/datepicker/demo/time.md @@ -9,35 +9,44 @@ ````jsx import { Datepicker, Timepicker } from 'antd'; -let result = new Date(); -let selectdDate, selectdTime; -function handleChange(from, value) { - if (!value) { +const DateTimePicker = React.createClass({ + handleChange(from, value) { + this.result = this.result || new Date(); + if (!value) { + if (from === 'date') { + this.selectedDate = false; + } else { + this.selectedTime = false; + } + return; + } if (from === 'date') { - selectdDate = false; + this.result.setFullYear(value.getFullYear()); + this.result.setMonth(value.getMonth()); + this.result.setDate(value.getDate()); + this.selectedDate = true; } else { - selectdTime = false; + this.result.setHours(value.getHours()); + this.result.setMinutes(value.getMinutes()); + this.result.setSeconds(value.getSeconds()); + this.selectedTime = true; } - return; - } - if (from === 'date') { - result.setFullYear(value.getFullYear()); - result.setMonth(value.getMonth()); - result.setDate(value.getDate()); - selectdDate = true; - } else { - result.setHours(value.getHours()); - result.setMinutes(value.getMinutes()); - result.setSeconds(value.getSeconds()); - selectdTime = true; - } - if (selectdDate && selectdTime) { - console.log('选择结果是:' + result); + if (this.selectedDate && this.selectedTime) { + this.props.onSelect(this.result); + } + }, + render() { + return
+ + +
; } +}); + +function onSelect(value) { + console.log('选择了时间:', value); } -ReactDOM.render(
- - -
, document.getElementById('components-datepicker-demo-time')); +ReactDOM.render( +, document.getElementById('components-datepicker-demo-time')); ```` diff --git a/components/timepicker/demo/basic.md b/components/timepicker/demo/basic.md index b1b77d953e..dd1256f82c 100644 --- a/components/timepicker/demo/basic.md +++ b/components/timepicker/demo/basic.md @@ -10,9 +10,11 @@ import { Timepicker } from 'antd'; function onChange(time) { - console.log(time.toLocaleTimeString('zh-CN', { - hour12: false - })); + if (time) { + console.log(time.toLocaleTimeString('zh-CN', { + hour12: false + })); + } } ReactDOM.render(