如何将单选按钮重置为默认状态或清除所有选中的单选按钮。 CODE
答案 0 :(得分:1)
您可以通过这种方式实现onReset
方法,以清除(或重置)表单中所有选定的单选按钮:
onReset = () => {
// Extract out cards from your state
var cards = this.state.cards
// Iterate each card..
cards.forEach(card => {
// Iterate each card option..
card.options.forEach(option => {
// Reset selected value of option
option.selected = false
})
})
// Apply "reset" card state to your component to cause a re-render
this.setState({ cards : cards })
}
以下是一个运行中的示例供您查看: https://stackblitz.com/edit/react-ujmlcz?file=index.js