问题描述
当Table
和onHover
都发生onClick
和js
事件时,我一直在尝试给css
上色,但是我也遇到相同的问题两者都..如果光标离开<tbody>
,则活动内容立即恢复为旧颜色。
我想做的是,当您单击表中的row
时,它将保持活动状态,直到单击另一个row
。
对于CSS解决方案,我使用的是此
:.hoverClass:hover {
background: red;
}
.hoverClass:active {
background: yellow;
}
对于js解决方案:
onTableRowClicked = (e) => {
this.setState({ currentColoringTarget: e });
e.currentTarget.style.background = "#EEE55E";
};
changeTableRowBackgroundOnMouseOver = (e) => {
e.currentTarget.style.background = "#EEEEEE";
};
changeTableRowBackgroundOnMouseOut = (e) => {
e.currentTarget.style.background = "transparent";
};
...
<tbody
onClick={(e) => this.onTableRowClicked(e)}
onMouseOver={this.changeTableRowBackgroundOnMouseOver}
onMouseOut={this.changeTableRowBackgroundOnMouseOut}
>
<tr>
<th className="vertically-aligned-th">
<strong>1)</strong>
</th>
<th className="vertically-aligned-th">21314</th>
<th className="vertically-aligned-th">address2</th>
<th>
<Button className="acceptButton">Accept</Button>
</th>
<th>
<Button className="declineButton">Decline</Button>
</th>
</tr>
</tbody>
...
这里是带有代码的CodeSandBox。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)