我试图提供某些表单元格的通态字形的能力。这是通过使用适当的CSS类来实现的,例如<i class="fa fa-check-square-o fa-2x foobar-stat-green"></i>
这是我到目前为止尝试过的JS:
function addRow(tableID,rowData) {
if (Array.isArray(rowData) && rowData.length>0) {
var myTab=document.getElementById(tableID).getElementsByTagName('tbody')[0];
var newRow = myTab.insertRow();
rowData.forEach(function (item) {
console.log(item);
var newCell = newRow.insertCell();
// THIS : createTextNode + appendChild = WORKS OK (no "err") !
//var newText = document.createTextNode(item);
//newCell.appendChild(newText);
// SWITCHING TO THIS = WORKS OK (no "err" in console)
//newCell.innerHTML='';
// BUT THIS YIELDS "err" in console
//newCell.innerHTML(item);
});
}
}
输入此功能的示例是:
var foobar = ['a','b','c','test+a@example.com','10/10/10 10:10','<i class="fa fa-check-square-o fa-2x foobar-status-green"></i>',false];
innerHTML
不是函数,它是属性,您不使用括号,直接写下:
newCell.innerHTML = item;
不必先写下:
newCell.innerHTML = ''; // not needed
newCell.innerHtml
不是元素上定义的函数。您需要将其用作设置器。newCell.innerHtml = item
。