我有以下JavaScript脚本:
<script>
var tabel = document.getElementById('tabel');
var order = document.getElementById('order');
var payment = document.getElementById('payment');
for(i=0;i<tabel.rows.length;i++){
if(tabel.rows[i].cells[1].innerHTML == "pending"){
order.style.backgroundColor = "red";
} else{
order.style.backgroundColor = "green";
}
}
</script>
我希望cells[1]
中的表格为红色背景,当值为&#34;待定&#34;时,绿色背景值为&#34;待定&#34;
我该怎么办?
答案 0 :(得分:0)
试试这个。这将使第二单元格的背景颜色变为红色或绿色,具体取决于第二单元格的值
var tabel = document.getElementById('tabel');
for(i=0;i<tabel.rows.length;i++){
if(tabel.rows[i].cells[1].innerHTML == "pending"){
tabel.rows[i].cells[1].style.backgroundColor = "red";
} else{
tabel.rows[i].cells[1].style.backgroundColor = "green";
}
}