简体   繁体   English

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

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

I've list of items and price in html table. 我在html表中列出了商品和价格。 i need to find low price in the item and change the background color of the cell in the html table . 我需要在该项目中找到低价,并更改html table单元格的背景颜色。

first Lowest value background-color is "Bue". 第一个最低价值的background-color是“ Bue”。

second lowest value background-color is "green". 第二最低的background-color是“绿色”。

third lowest value background-color is "orange". 第三最低的background-color是“橙色”。

My Table is: 我的表是:

Item-Name Price 产品名称价格

A 12 A 12

A 18 18岁

A 9 A 9

A 13 A 13

B 5 B 5

B 8 B 8

B 12 B 12

Expected Result: 预期结果:

Item-Name Price 产品名称价格

A 12 A 12

A 18 18岁

A 9 A 9

A 13 A 13

B 5 B 5

B 8 B 8

B 12 B 12

In this Expected result table I've given <h1> tag for first lowest value, <h2> for second lowest value and `' for third lowest value. 在此预期结果表中,我给<h1>标签指定了第一个最低值,给了<h2>标记了第二个最低值,并给了''代表了第三个最低值。

I don't know how to change background color in this question so that I've given Header tags 我不知道如何在这个问题中更改背景颜色,所以我给了Header tags

Please help me how to find low values using jquery . 请帮助我如何使用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