这是我的HTML表格:
<table class="kobel_days_table" id="kobel_days_table" style="display: none;">
<tr>
<th>Wochentag</th>
<th>Datum</th>
<th>Thema</th>
<th>Kobelwirte</th>
</tr>
</table>
并使用js我添加值:
//Zeile erstellen
var y = document.createElement([doc.id]);
y.setAttribute("id", [doc.id]);
document.getElementById("kobel_days_table").appendChild(y);
//Spalten in einer Zeile
var y = document.createElement("TR");
y.setAttribute("id", [doc.id]);
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode(kobel_days_info[0]);
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode(kobel_days_info[1]);
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode(kobel_days_info[2]);
c.appendChild(d);
y.appendChild(c);
var e = document.createElement("TD");
var f = document.createTextNode(kobel_days_info[3]);
e.appendChild(f);
y.appendChild(e);
document.getElementById("kobel_days_table").appendChild(y);
最后这里是CSS:
.kobel_content table {
border-collapse: collapse;
width: 100%;
}
.kobel_content th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
现在我的问题。这是一个理解助手的图像:https://www.dropbox.com/s/rjxuih67qpgr7o7/bug.PNG?dl=0 值不以值为中心。 “Montag”应该以“Wochentag”,“05.03”在“Datum”之下为中心等等......但无论如何它都不起作用。 〜菲利普
问题可能是你没有使用<thead>
和<tbody>
标签。见here。
//Spalten in einer Zeile
var y = document.createElement("TR");
y.setAttribute("id", 'what-id');
//Spalten in einer Zeile
var cE = document.createElement("TD");
var tE = document.createTextNode('test');
cE.appendChild(tE);
y.appendChild(cE);
var a = document.createElement("TD");
var b = document.createTextNode('test');
a.appendChild(b);
y.appendChild(a);
var c = document.createElement("TD");
var d = document.createTextNode('test');
c.appendChild(d);
y.appendChild(c);
var e = document.createElement("TD");
var f = document.createTextNode('test');
e.appendChild(f);
y.appendChild(e);
document.getElementById("kobel_days_table").children[1].appendChild(y);
.kobel_content table {
border-collapse: collapse;
width: 100%;
}
.kobel_content th, td {
padding: 8px;
text-align: left;
border-bottom: 1px solid #ddd;
}
<table clas="kobel_days_table" id="kobel_days_table">
<thead>
<tr>
<th>Wochentag</th>
<th>Datum</th>
<th>Thema</th>
<th>Kobelwirte</th>
</tr>
</thead>
<tbody></tbody>
</table>