如何在反应中对单选按钮进行默认检查? [英] How to make default checked for radio buttons in react?

查看:37
本文介绍了如何在反应中对单选按钮进行默认检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何让单选按钮检查初始值是否为真?

How to make the radio button checked if the initial value is true?

推荐答案

使用 defaultChecked 属性,可用于 和 <代码><input type="radio"> - https://reactjs.org/docs/uncontrolled-components.html#default-values

Using the defaultChecked property, available for <input type="checkbox"> and <input type="radio"> - https://reactjs.org/docs/uncontrolled-components.html#default-values

<input type="radio" name="radio-group" value="1" defaultChecked />
<input type="radio" name="radio-group" value="2" />
<input type="radio" name="radio-group" value="3" />

这篇关于如何在反应中对单选按钮进行默认检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆