TLDR:使用defaultChecked而不是选中,在这里工作jsbin
http://jsbin.com/mecimayawe/1/edit?js,output
尝试设置一个简单的复选框,当它被选中将交叉标签文本。由于某种原因,当我使用组件时,handleChange不会被触发。任何人都可以解释我做错了什么?
var CrossoutCheckbox = React.createClass({
getInitialState: function () {
return {
complete: (!!this.props.complete) || false
};
},
handleChange: function(){
console.log('handleChange', this.refs.complete.checked); // Never gets logged
this.setState({
complete: this.refs.complete.checked
});
},
render: function(){
var labelStyle={
'text-decoration': this.state.complete?'line-through':''
};
return (
type="checkbox"
checked={this.state.complete}
ref=