Jquery让table行根据单元格值变色

  1. 先注意表格不要引类似分行变色的css,如table-striped
  2. View下方式
    1. foreach下方式

  @foreach (var item in Model)

  {  <tr style="background-color:@{if (item.ReceQuantity>=item.BuyQuaity ){<text>lightgreen</text>}};">

  1. jquery方式

     $("#grd").find("tr").each(function () {

         var v1 = parseFloat($(this).children('td:eq(8)').text());    //取行第8列值

         var v2 = parseFloat($(this).children('td:eq(9)').text());

         if (v1 == v2) {

             $(this).css({ "color": "darkgreen", "font-weight": "bold" });   //多CSS方式

         } else {

             $(this).css("color", "dark");

         }

 });

posted @ 2017-11-04 10:25  沙闻  阅读(1543)  评论(0编辑  收藏  举报