0
我有以下代碼動態更新表的細胞純javascript
body = document.body;
tbl = document.createElement('table');
tbl.setAttribute('id','tab');
document.body.style.background = "rgba(0, 0, 0, 0.4)"
tbl.contentEditable = 'true';
tbl.style.border = '1px solid white';
tbl.style.backgroundColor = '#ffffff';
tbl.style.width = '25%';
tbl.style.marginBottom = '1300px';
tbl.style.marginLeft = '500px';
tbl.style.transform ='translateY(50%)'
txt = ['Transfer Status','File name: ', 'Bytes Transferred: ', '% Transferred: '];
var divContainer = document.createElement('div');
divContainer.setAttribute('id','container');
divContainer.contentEditable = 'true';
for(var i = 0; i < 4; i++){
var tr = tbl.insertRow();
var td = tr.insertCell();
td.appendChild(document.createTextNode(txt[i]));
td.appendChild(divContainer);
}
body.appendChild(tbl);
下面的代碼被稱爲每次文件被傳輸並且存在要傳送的另一個文件的時間。
var table = document.getElementById('tab');
var trs = table.getElementsByTagName('tr');
var tds = table.getElementsByTagName('td');
var fname = txt[1] + CurrentFileName;
var Btransf = txt[2] + BytesTransferredThisFile + ' of ' + TotalBytesThisFile;
var transf = txt[3] + strPerc_1;
var vl = ['',fname,Btransf,transf];
tds[1].innerHtml = vl[1];
tds[2].innerHtml = vl[2];
tds[3].innerHtml = vl[3];