首页 > 其他 > 详细

checkbox事件的变化

时间:2017-07-25 11:46:35      阅读:398      评论:0      收藏:0      [点我收藏+]
<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事件, 回调函数中就可以得到正确的值了。

checkbox事件的变化

原文:http://www.cnblogs.com/cndotabestdota/p/7233159.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!