如何獲取單選按鈕的值,如果我在RadioGroup中調用updateRadioButton,則會導致錯誤。我需要在控制檯中使用(react-radio-buttons)作爲男性或女性進行打印。單選按鈕打印正確,但我無法獲得價值。先謝謝你。如何獲取Reactjs中的單選按鈕(react-radio-buttons)的值?
class CreateUserComponent extends React.Component {
constructor(props) {
super(props);
this.state={radio:''}
}
updateRadioButton(e) {
this.setState({ radio: e.target.value });
}
<RadioGroup horizontal>
<RadioButton value="Male">Male</RadioButton>
<RadioButton value="Female">Female</RadioButton>
</RadioGroup>
謝謝@ Sag1v – PremKumar
@PremKumar沒有問題,iv'e增加了運行的片段與您的代碼 –
哇,太謝謝你了:-) – PremKumar