【发布时间】:2021-06-11 19:45:18
【问题描述】:
在一个 React 项目中,我使用单选按钮列出日历日期和日期。我的意图是更改这些单选按钮的背景颜色并保留它。单击屏幕时它不应消失。
以下为参考代码:
{newDate.map((data, i) => (
<ButtonGroup toggle style={{ width: "100%" }}>
<GridListTile style={gridListStylePhoto}>
<h5>{currday(data.getDay())}</h5>
<ToggleButton
key={i}
type="radio"
active="true"
variant="light"
name="radio"
value={currday(data.getDay()) + " " + data.getDate()}
checked={radioValue === data.getDate()}
onChange={(e) => {
handleChange(e);
}}
>
<br />
{data.getDate()}
</ToggleButton>
</GridListTile>
</ButtonGroup>
))}
以下是样式参考:
input[type="checkbox"],
input[type="radio"] {
display: none;
}
.btn-light {
background-color: transparent;
border: transparent;
}
.btn-light:checked {
background-color: red // Here is color doesn't change
}
为了改变上述单选按钮的背景颜色可以做些什么?
请参考下面的 Codesandbox 链接。
【问题讨论】:
-
您的问题没有提及有关单击/选择电台的任何内容。请更新它
-
好的,那么最好的解决方案是什么?
-
1.请edit 并使用您在 cmets 中提供的信息更新问题,例如“我的意思是当单选按钮在选择时处于活动状态” 2. 您的
demo.js有很多样板代码。请参阅minimal reproducible example。当您更新问题时,它会在活动源中遇到问题