[英]How to make a checkbox behave like a radio button in react
如何使引導復選框在反應中表現得像一個單選按鈕?。 我在表中有一個動態加載的行,每行都包含接受和拒絕復選框,我希望這些復選框的行為類似於單選按鈕。 我不能使用單選按鈕,所以需要一種方法讓復選框表現得像單選按鈕。
<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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.