【发布时间】:2020-07-09 22:21:34
【问题描述】:
我在一个表单中有几个单独的复选框。但我不知道如何在提交后清除复选框。
const App = () =>{
const funct1 = (e) => {
if(e.target.checked){
//some function
}
}
const funct2 = (e) => {
if(e.target.checked){
//some function
}
}
const funct3 = (e) => {
if(e.target.checked){
//some function
}
}
const submitForm= (e) => {
//some function
}
return(
<div>
<div>
Pear <Checkbox onChange={(e)=>funct1(e)} />
</div>
<div>
Apple <Checkbox onChange={(e)=>funct2(e)} />
</div>
<div>
Orange <Checkbox onChange={(e)=>funct3(e)} />
</div>
<Button onClick={(e) => submitForm(e)}> Submit </Button>
</div>
)
}
我已阅读有关useRef 的信息,但我不确定它在这种情况下如何帮助我。谁能向我解释在这种情况下是否可以使用useRef 来帮助我实现我想要的?
【问题讨论】: