checkbox事件的变化

<input type="checkbox" checked={this.state.checked} onChange={this.checkedChangeHandler} />记住账号</span>

checkedChangeHandler: function(event) {
this.setState({
checked: event.target.checked
});
},

页面有一个checkbox,默认选中,并且绑定了click事件。在事件的回调函数中使用event.target.checked检查checkbox的最新值。

用户通过鼠标点击checkbox,在回调函数中,event.target.checked的值是false,没问题。

在Jasmine中,如果用jQuery触发click事件,在回调函数中,event.target.checked的值是true,回调函数执行完毕之后,checkbox才变成非选中的状态。

解决办法:

使用document.getElementById获得checkbox,然后触发click事件, 回调函数中就可以得到正确的值了。

原文地址:https://www.cnblogs.com/cndotabestdota/p/7233159.html