繁体   English   中英

使用项目名称查找最低值,并使用jquery更改html表中的低值背景色

[英]find lowest value by using item name and change low value background color in html table using jquery

我在html表中列出了商品和价格。 我需要在该项目中找到低价,并更改html table单元格的背景颜色。

第一个最低价值的background-color是“ Bue”。

第二最低的background-color是“绿色”。

第三最低的background-color是“橙色”。

我的表是:

产品名称价格

A 12

18岁

A 9

A 13

B 5

B 8

B 12

预期结果:

产品名称价格

A 12

18岁

A 9

A 13

B 5

B 8

B 12

在此预期结果表中,我给<h1>标签指定了第一个最低值,给了<h2>标记了第二个最低值,并给了''代表了第三个最低值。

我不知道如何在这个问题中更改背景颜色,所以我给了Header tags

请帮助我如何使用jquery查找低值。

`https://jsfiddle.net/eradi_singh/gokrrucr/6/` 

请检查此小提琴以获取您的答案。

<script>

var valArr = [];

$('tbody tr td:nth-child(0)').each(function () {
  valArr.push(parseInt($(this).text()));
});

valArr.sort(function(a, b){return a-b});

$('tbody tr td:nth-child(0)').each(function () {
  if(parseInt($(this).text()) == valArr[0]){
     //Color Lowest Row
  }else if(parseInt($(this).text()) == valArr[1]){
     //Color Second Lowest Row By getting Parents
  }else if(parseInt($(this).text()) == valArr[2]){
    //Color Third Lowest Row By getting Parents
  }

});
</script>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM