【发布时间】:2021-11-05 04:08:37
【问题描述】:
我在.map 方法中有一个单选按钮,第一个被选中defaultChecked={index === 0},我如何在这里获得option 的值?不使用普通的 javascript
const [optionData, setOptionData] = useState({})
{variant.options.map((option, index) => {
<input
type="radio"
name="variant-select"
id="variant-select"
className="focus:ring-0 focus:ring-offset-0 focus:text-red-600 text-red-600 border-none -mt-1 cursor-pointer z-10"
defaultChecked={index === 0}
value={index}
onClick={(e) => {
setOptionData(option)
}
}}
/>
}
}
【问题讨论】:
-
你想从哪里获得期权的价值?
-
对不起,我没听懂你的问题。 @越南
-
how do I get the value of the option here。here是什么? -
这里,我的意思是当它被默认选中时
-
当用户点击不同的单选按钮时,我可以这样做
onClick={(e) => { setOptionData(option) } }}
标签: javascript reactjs radio-button