javascript - 如何正确显示/隐藏表格 TD 的右边框
问题描述
我想灵活地隐藏/显示表格内某些 TD 的右边框,但 TD 的边框颜色可能不同,例如红色、黑色或蓝色,所以我不能只做下面这样的事情:
td.style.borderRightColor = shouldShow ? 'black' : 'white';
因为 td 边框可以是任何颜色和任何背景,例如
<td style="border:1px solid rgb(xx, yy, zz);width:100px"></td>
相反,我想知道是否有办法使 TD 的边框透明。就像,将边框的 RGBA 的 A 设置为 0,但是为了做到这一点,我首先需要知道边框的当前 RGB?或者,有没有其他方法可以做到这一点?
解决方案
您可以使用border-width
. 或者在你的情况下,border-right-width
:
const borderWidth = '1px'; // this will depend on what width you're using already.
const noBorderWidth = '0';
td.style.borderRightWidth = shouldShow ? borderWidth : noBorderWidth ;
或border-style
( border-right-style
):
const borderStyle = 'solid'; // this will depend on what border-style you're using already.
const noBorderStyle = 'none';
td.style.borderRightStyle = shouldShow ? borderStyle : noBorderStyle;
推荐阅读
- python-2.7 - 在 2020 年 Python 2 生命周期结束后,我还能通过 Pip 安装依赖包吗?
- php - Laravel 中的多重审批流程
- loops - 如何在谷歌工作表编辑器脚本中循环 getRange("B" + row + " :" + "J" + row)
- linux - 如何在 bash 中找到一些文件并将它们输入到另一个程序中?
- python-3.5 - AttributeError:模块 'shutil' 没有属性 'copy'
- c++ - 子窗口处于焦点时未调用 WinAPI 计时器回调
- hibernate - Hibernate PersistenceSet 和 Lombok EqualsAndHashCode 问题
- python - 熊猫:groupby 操作后如何取回原始索引
- javascript - 页面刷新后保持滚动位置并保存切换
- c++ - 在 C++ 中初始化变量