如何正确显示/隐藏表格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;

最新更新