如何在单选按钮上单击以获取div中的值?

时间:2019-06-07 05:54:31

标签: reactjs radio-button

我试图通过单选按钮单击在div中获取该值(该值是从数组中获取的)。如何获取该值?

fn(){
value
}
{id1 && id1.map(list =>
<div style={{padding:'6px 6px'}}> 
  {"ClaimID:"+ list.ID+' '+'-'+"PatientID:"+list.RCID+' '+'-'+' '+"Amount:" +new Intl.NumberFormat('en-USD', {currency: 'USD' ,style: 'currency'}).format(Number(list.Amount))} 
 <input type='radio' name={'PatientID: ' + list.RCID} vlaue={'PatientID: ' + list.RCID} style={{width: '50px'}} />  </div>)} 

like this

1 个答案:

答案 0 :(得分:2)

虽然您的问题不清楚,但我认为您可以使用以下代码:

state = {
  selectedRadioValue: null
}

changeRadioButton = (e) => {
  if(e.target.value == true){
    this.setState({
      selectedRadioValue : e.target.value
    })
  }
}

render() {
  return(
    <div>
      <input type='radio' onChange= {(e) => {this.changeRadioButton(e)}}/>
      <input type='radio' onChange= {(e) => {this.changeRadioButton(e)}}/>
    </div>
  )
}