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

前端 未结 5 592
爱一瞬间的悲伤
爱一瞬间的悲伤 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:29

    You could use code like this:

    $(".colorMe td").each(function() {
        var val = parseInt(this.innerHTML, 10);
        if (val < 3000) {
            this.style.backgroundColor = "#F00000";
        }
    });
    

    See a working example here: http://jsfiddle.net/jfriend00/GAwrB/.

提交回复
热议问题