javascript - 如何使复选框在反应中表现得像单选按钮
问题描述
如何使引导复选框在反应中表现得像单选按钮?我在表中有一个动态加载行,每行都包含接受和拒绝复选框,我希望这些复选框的行为类似于单选按钮。我不能使用单选按钮,所以需要一种方法来使复选框的行为类似于单选按钮。
<div className="custom-control custom-checkbox">
<input
type="checkbox"
className="custom-control-input"
id={page + item.RowKey + "Accept"}
name={page + item.RowKey + "Accept"}/>
<label
className="custom-control-label"
htmlFor={page + item.RowKey + "Accept"}>
Accept
</label>
</div>
<div className="custom-control custom-checkbox">
<input
type="checkbox"
className="custom-control-input"
id={page + item.RowKey + "Reject"} />
<label
className="custom-control-label"
htmlFor={page + item.RowKey + "Reject"}>
Reject
</label>
</div>
解决方案
您可以使用ref
复选框,并且onClick
对于每个复选框,ref
您可以取消选中该框。
以下是关于 ref 的一些文档:https ://reactjs.org/docs/refs-and-the-dom.html
推荐阅读
- pyspark - 当其中一些在 pyspark 中为空时发现时间戳的差异
- reactjs - 如何在 typescript + React 中为 Object 类型的可选嵌套道具提供默认值?
- python - 无法编辑列表
- python - 范围内的单词(列表)[Python]
- python - 在 Python 中对列表进行排序以使其相应索引处于相似时间戳的快速方法?
- flutter - 合并飞镖中的两个列表对象
- node.js - Discord.js TypeError:无法读取 null 的属性“角色”
- assembly - 如何使用 Irvine32 并以有限的精度以十进制而不是科学计数法显示浮点数?
- java - 为什么 Java 记录的规范构造函数没有比记录级别更严格的访问权限?
- php - 相关文章 PHP (Wordpress) 的问题