conditional formatting of html table cells

前端 未结 6 1272
鱼传尺愫
鱼传尺愫 2021-02-04 12:49

Are there any out of the box solutions to have conditional formatting of HTML tables?

With conditional formatting I am more interested in having different colors as cell

6条回答
  •  闹比i
    闹比i (楼主)
    2021-02-04 13:24

    http://jsfiddle.net/stofke/Ya68Q/

          $(function() {
                $('tr > td:odd').each(function(index) {
                    var scale = [['vPoor', 10], ['poor', 50], ['avg', 250], ['good', 1250], ['vGood', 6250]];
                    var score = $(this).text();
                    for (var i = 0; i < scale.length; i++) {
                        if (score <= scale[i][1]) {
                            $(this).addClass(scale[i][0]);
                        }
                    }
                });
           });
    

提交回复
热议问题