【发布时间】:2021-05-27 03:22:40
【问题描述】:
我使用变量设置的复选框总是返回变量的值,并且复选框总是被选中。 如果值为 true,则返回 true,反之亦然
answerOption={isCorrect:true}
<input type="checkbox" checked={(!answerOption.isCorrect) ? false : true} onChange={this.updateAnswerChecked.bind(this)} style="cursor:pointer;" />
updateAnswerChecked(e){
console.log(e.target.checked);
answerOption.isCorrect = e.target.checked
}
【问题讨论】:
-
你不能像那样触发重新渲染,你需要使用 setState