简体   繁体   English

通过DOM删除HTML表格的可见网格

[英]Remove visible grid of HTML Table through DOM

I'm currently trying to remove the borders of a simple table through DOM-Code. 我目前正试图通过DOM-Code删除简单表的边框。 None of the solutions I found in the internet worked: 我在互联网上找到的解决方案都没有奏效:

var table = document.createElement("table");
... Add elements into table ...
table.style.borderCollapse = "collapse";
table.style.border = "none";
table.style.outline = "none";
table.style.cellPadding = "0";
table.style.cellSpacing = "0";
... for each cell in the table ...
    var td = ...
    td.style.cellPadding = "0";
    td.style.cellSpacing = "0";

Also, even if it would work, I don't like the solution, because I actually WANT to have padding and spacing on my cells, I just want to remove the visible grid. 此外,即使它可以工作,我不喜欢这个解决方案,因为我实际上想要在我的单元格上填充和间距,我只是想删除可见的网格。 (In my case I'm using a table to "order"/"set the position" of different elements) So how do I remove those borders, and is it possible without removing padding and spacing? (在我的情况下,我使用表来“排序”/“设置不同元素的位置”)那么如何删除这些边框,是否可以不删除填充和间距?

Try using the following attribute: table border 尝试使用以下属性:表格边框

1 = cell border on 1 =单元格边框
0= cell border off 0 =关闭单元格边框

I checked all of my included files, and noticed that one external JavaScript-File set the border of all tables to 1 by default, thus causing this problem to occur. 我检查了所有包含的文件,并注意到一个外部JavaScript文件默认将所有表的边框设置为1,从而导致出现此问题。

By removing the dependency, the border also gets removed. 通过删除依赖项,边框也会被删除。 What I don't understand, is why that "border"-line didn't get overridden by my code... 我不明白,为什么“边界”线没有被我的代码覆盖...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM