我有一个预定义的表,所有行都隐藏在这样:
<tr id="row1" style="display: none;">
</tr>
<tr id="row2" style="display: none;">
</tr>
<tr id="row3" style="display: none;">
</tr>
<tr id="row4" style="display: none;">
</tr>
<tr id="row5" style="display: none;">
</tr>
<tr id="row6" style="display: none;">
</tr>
我正在尝试使用Javascript向每行添加单元格然后显示它。我的javascript目前获取行ID,最后它将显示该行。但我无法弄清楚如何添加细胞,这里是我的功能:
function CreateTable(numberOfLines, linesCollection, displayCollection) {
for (var i = 0; i < numberOfLines; i++) {
var rowId = 'row' + (i + 1);
var row = document.getElementById(rowId);
document.getElementById('row' + (i + 1)).style.display = "";
}
}
答案 0 :(得分:1)
试试这个
var row = document.getElementById(rowId);
var TD = document.createElement('td'); //Create new cell
TD.innerHTML = 'This is a new cell added'; //Set some thing
row.appendChild (TD); //Add it to row