P粉5452181852024-04-07 09:07:36
按照您的要求,您可以将handleCheckboxQuestionInput更改为:
const handleCheckboxQuestionInput = (e) => { const answer = e.target.value; setSelectedAnswers((prevAnswers) => { if(prevAnswers.includes(answer)) { return prevAnswers.filter(e => e !== answer) } else { return [...prevAnswers, answer] } }); };
并在输入元素处更改为:
handleCheckboxQuestionInput(e)} />
希望对你有帮助