如何删除表格的单元格边框?

缺口

如何通过JavaScript从表格中删除第一个单元格的边框?(最终,如图所示)

var firstRow = document.getElementById("tbl1").rows[0].cells;
//Get first cell
//firstRow[0].style.REMOVE CELL BORDER
//Get 2nd row of tbl1
var secRow = document.getElementById("tbl1").rows[1].cells;
//Get 5th cell
secRow[4].style.backgroundColor = 'darkBlue';
//Get 4th row of tbl1
var fouthRow = document.getElementById("tbl1").rows[3].cells;
//Get 3rd, 4th and 5th cell
fouthRow[2].style.backgroundColor = 'darkBlue';
fouthRow[3].style.backgroundColor = 'darkBlue';
fouthRow[4].style.backgroundColor = 'darkBlue';
//Get 7th row of tbl1
var seventhRow = document.getElementById("tbl1").rows[6].cells;
//Get 2nd, 3rd cell
seventhRow[1].style.backgroundColor = 'darkBlue';
seventhRow[2].style.backgroundColor = 'darkBlue';

本质上,我想从表中删除单元格。如果有更好的方法来获得期望的结果,我很好。谢谢!

所需结果

mkbctrl

针对您的问题,我提出了2个想法。

第一个:

如果您不关心单元格的对齐方式(但我相信您会..),则可以这样定位td

const myTable = document.querySelector('#myTable tbody')
const myRows = document.querySelectorAll('#myTable tr')
const childToRemove = myRows[0].children[0]

并像这样删除它: myRows[0].removeChild(childToRemove)

但是,为了保持UI完整,我可能会采用以下解决方案:

const myTable = document.querySelector('#myTable tbody')
const myRows = document.querySelectorAll('#myTable tr')
const childToRemove = myRows[0].children[0]

childToRemove.style.borderColor = 'white'
childToRemove.style.color = 'white'
childToRemove.style.pointerEvents = 'none'

这是一个JSfiddle:https ://jsfiddle.net/mkbctrlll/Lumjcy7d/35/

希望这可以帮助

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何从表格单元格中删除填充和边框?

HTML,从表格的左上角单元格删除边框

如何删除边框并更改表格左上方单元格的背景颜色?

空时如何突出显示表格单元格边框?

如何设置表格边框小于单元格高度

HTML:如何使表格单元格边框向内增长

如何调整表格单元格边框的样式?

如何防止表格单元格边框被单元格图像剪切?

表格单元格的边框颜色变化

使用表格边框的类时,如何使某些表格单元格边框消失?

如何删除 WPF 网格单元格之间的小边框?

删除jtable中的单元格边框

如何从 HTML/CSS 中的表格中删除单元格?

如何使用 JQuery 删除表格单元格的某些元素

如何从表格单元格中删除填充?

如何删除表格单元格中的空白空间?

如何从表格中删除单元格标签?

如何删除Google表格中列的空白单元格?

单击单元格时如何删除表格中单元格的轮廓?

NSTableView删除表格视图边框和单元格之间的填充/空格

使表格单元格的边框为表格宽度的100%

如何为表格单元格边框的角指定上/下边框而不是左/右边框的颜色

删除表格单元格之间的空白

删除表格单元格末尾的空白

跨表格中的单元格后如何修复空白边框?

如何摆脱此表格左上方单元格中的边框?

CSS / Firefox-打印多个页面时,如何显示表格单元格边框?

如何根据单元格数据长度c#制作表格边框长度?

如何将矩形形状与表格单元格边框对齐?