Can I make a table cell have a different background color if the value =< a particular number with jquery or PHP?

前端 未结 5 497
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-28 17:31

I have an HTML table with a lot of numbers.

Is it possible to have a table cell change background color if the value inside that cell (or column) equals or is less than

5条回答
  •  醉话见心
    2021-01-28 18:22

    Try this one

    var table = document.getElementById("tableId");
    var row = table.rows[rowIndex];
    var cell = row.cells[cellIndex];
    
    var cellValue = Number(cell.innerHTML);
    
    if (cellValue > 3000)
      cell.style.backgroundColor = "red";
    

提交回复
热议问题