2015-09-26 50 views
0

我正在嘗試將附加的event_type提交給從單選按鈕中選擇的選項。例如,如果「專業」是選擇的選項,我想將event_type設置爲提交的數據。還將「活動」類設置爲當前選定的標籤。我想弄清楚如何做到這一點。任何幫助?由於使用ReactJs提交廣播輸入並將活動類別設置爲當前選擇

<label htmlFor="professional" className="EventTypeFieldButton EventTypeFieldProfessional active"> 
    <span className="TypeDot"></span>Professional 
</label> 
<input type="radio" name="event_type" id="professional" value="professional" /> 
<label htmlFor="academic" className="EventTypeFieldButton EventTypeFieldAcademic"> 
    <span className="TypeDot"></span>Academic 
</label> 
<input type="radio" name="event_type" id="academic" value="academic" /> 
<label htmlFor="miscellaneous" className="EventTypeFieldButton EventTypeFieldMiscellaneous"> 
    <span className="TypeDot"></span>Miscellaneous 
</label> 
<input type="radio" name="event_type" id="miscellaneous" value="miscellaneous" /> 

回答

1
var MyComponent = React.createClass({ 

    render: function() { 
    <label className={this.state.isActive}> 
      <input type="radio" name="event_type" id="professional" value="professional" onChange={this._onselectRadio(e)} /> 
    </label> 

    }, 

    _onselectRadio: function(e) { 
     var event_type= e.target.name; 
     // submit stuff 
     this.setState({ 
      isActive = "active" 
     }); 
    } 



}); 

既然你有幾個標籤,你就必須動態地呈現您的無線輸入和檢查e.target.name等於你的標籤ID /名稱,類似的東西。

相關問題