取消选中反应中的单选按钮 [英] Uncheck radio buttons in react
本文介绍了取消选中反应中的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我认为这是一个非常愚蠢的疑问,但是我对此深感困惑. 我有多个单选按钮,我想在单击另一个单选按钮后立即取消选中所有单选按钮. 如何在反应中实现它?
I think its a very silly doubt but I am stuck in this.. I have multiple radio buttons and I want to uncheck all the radio buttons as soon as I click the other radio button. How can I achieve it in react?
var options = [{id:1,nm:"Appointment fixed"},{id:2,nm:"Call later"},{id:3,nm:"Wrong number"},{id:4,nm:"Don't call again"},{id:5,nm:"Call later"}];
{options.map((item,i) => {
return (
<div onChange={(i)=>this.callOptions(i)}>
<label className="radio-inline"><input type="radio" value={i} ref={'ref_' + i} value={item.id}/>{item.nm}</label>
</div>
)
})}
推荐答案
为您提供一个通用名称属性单选按钮.更改
Give a common name attribute for you radio button. Change
<input type="radio" value={i} ref={'ref_' + i} value={item.id}/>
到
<input type="radio" value={i} name="abc" ref={'ref_' + i} value={item.id}/>
这篇关于取消选中反应中的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文