javascript - react,獲取radio的值出錯
問題描述
代碼是這樣的(刪了一部分,只留了有問題的
class NewGateway extends React.Component { handleSubmit(e) {var gw = form2json(’#newGatewayForm’);console.log('gw', gw); } render() {return <Form horizontal id='newGatewayForm'> <FormGroup controlId='formRegister'><Col componentClass={ControlLabel} sm={2}><T.span text='Register'/></Col><Col sm={10}> <Radio name='register' value='yes' inline><T.span text='yes'/></Radio> <Radio name='register' value='no' inline><T.span text='no'/></Radio></Col> </FormGroup></Form> }}
獲取gw.register,總是獲得no,就是無論選哪個radio,得到的都是后面那個radio的值。
問一下原因和怎么修改
問題解答
回答1:form2json 是哪個庫的? 建議 react 應該用 state 去管理 radio 的值.(包括其他 form 元素)
相關文章:
1. javascript - react 中各個聲明周期中異步的執行順序2. javascript - react性能問題?3. javascript - react如何獲取offsetX?4. javascript - react-router-dom 跳轉問題js5. javascript - Reactjs關于函數內跳轉 this.context.router.push(path)的問題6. javascript - react+百度地圖7. javascript - react我用了antdesign的table控件,我怎么強制用自己的style覆蓋掉調用的class的某個屬性8. javascript - react native使用第三方開源插件的時候報錯解析不了模塊9. javascript - react配合fetch報錯問題10. javascript - react-native在chrome調試工具中出現警告,并且不能使用react dev-tools
