JavaScript从动态创建的表中自定义文本

JavaScript从动态创建的表中自定义文本,javascript,html,Javascript,Html,我在尝试使用JavaScript向HTML动态添加表时遇到了一些问题 我得到了一个数组,我的样本数据是[0,0,5,2,7,5,4,5,0] 我的HTML: <div id="ftw" style="min-width:80px; overflow:auto; overflow-x:hidden; overflow-y:hidden; display:none;"> <table id="ft" class="table" style="font-size:13.5px

我在尝试使用JavaScript向HTML动态添加表时遇到了一些问题

我得到了一个数组,我的样本数据是
[0,0,5,2,7,5,4,5,0]

我的HTML:

<div id="ftw" style="min-width:80px; overflow:auto; overflow-x:hidden; overflow-y:hidden; display:none;">
    <table id="ft" class="table" style="font-size:13.5px">

    </table>
</div>
我想做一些类似于当
项==0
时,然后将字体设置为红色。如果
item>0
,我想将
项加粗

有什么办法可以做到这一点吗?

这里是

我将
td.textContent
更改为
td.innerHTML
,并添加
row.style.color=“red”
addCell(行,'每'+项+'天)

函数addCell(tr,text){
var td=tr.insertCell();
td.innerHTML=文本;
返回td;
}
dataset.forEach(函数(项){
var row=table.insertRow();
如果(项==0){
row.style.color=“红色”;
addCell(行“无记录”);
}否则{
addCell(行,'每'+项目+'天');
}
});

你能发布尝试吗?你想要这个吗?是的,类似这样的东西。但是如果项目大于0,我只想加粗数字检查我的答案@hyperfkcb
document.getElementById('ftw').style.display = 'block';
        var table = document.getElementById("ft");

        // helper function        
        function addCell(tr, text) {
            var td = tr.insertCell();
            td.textContent = text;
            return td;
        }
 function addCell(tr, text) {
            var td = tr.insertCell();
            td.innerHTML = text;
            return td;
        }



dataset.forEach(function (item) {
            var row = table.insertRow();
            if(item == 0){
            row.style.color="red";
                addCell(row, 'No record');
            }else{  
                addCell(row, 'Every <b>' + item + '</b> day(s)');

            }
        });