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 應(yīng)該用 state 去管理 radio 的值.(包括其他 form 元素)
相關(guān)文章:
1. javascript - react如何不通過state去修改classname?2. javascript - react 中如何自動播放視頻video3. javascript - react 組件 使用super()報錯4. javascript - react route 4.1在事件里面跳轉(zhuǎn)路由5. javascript - react 中綁定事件和阻止事件冒泡6. javascript - React中組件綁定this7. javascript - react input file8. javascript - react的ui庫問題9. javascript - react-router 4.0版本怎么實現(xiàn)以前onEnter的效果10. javascript - react性能問題?
