答案很全了啊,我就补个react的吧
//index.js
var SpanBox = React.createClass({
getDefaultProps: function () {
return {
count: 0
}
},
render: function () {
var temp = this.props.count;
if (temp < 10 && temp >= 0)
temp = '0' + temp
else if (temp < 0 && temp > -10)
temp = '-0' + Math.abs(temp);
return
}
});
var MainBox = React.createClass({
increaseHandler: function () {
if (++this.state.count > 30)
this.setState({
count: 0
})
else
this.setState({
count: this.state.count
})
},
reduceHandler: function () {
if (--this.state.count < 0)
this.setState({
count: 30
})
else
this.setState({
count: this.state.count
})
},
getInitialState: function () {
return {
count: 0
}
},
render: function () {
return (
增加
减少
)
}
})
React.render(, document.body);
//html
//index.js用babel转一下再用