var AlarmClock =React.createClass({
getInitialState: function() {
return {
Atime: '请输入闹钟倒计秒,再点击确定按钮'
}
},
updateAtime: function(e) {
this.setState({Atime: e.target.value})
},
start: function() {
this.setState({Atime: this.state.Atime - 1});
},
componentDidMount: function() {
this.interval = setInterval(this.start, 1000);
},
render:function (){
return(
<div>
<input type="text" onChange={this.updateAtime} />
<button onClick={this.start}>开始</button>
<p>{this.state.Atime}</p>
</div>
)
}
})
判断数字用正则表达式
`function(s) {
let regExp = /[0-9]*/;
return regExp.test(s);
}`