如何清除单选按钮/将所有选定的单选按钮清除为错误状态。反应 - bootstrap
How to clear radio buttons / clear all selected radio buttons to false state. reactjs - bootstrap
如何将单选按钮重置为默认状态或清除所有选定的单选按钮。
CODE
您可以通过这种方式实现 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
如何将单选按钮重置为默认状态或清除所有选定的单选按钮。 CODE
您可以通过这种方式实现 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