0

.csv ファイルに在庫リストがあり、Joomla で CSV to table プラグインを使用してすべてのデータを表示しています。

プラグインが作成するものは..

<table class="arttable_table">
  <thead>
    <tr>
      <th class="header0">Aricle</th>
      <th class="header1">amount</th><th class="header2">minimum amount</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td class="cell0">Coffee</td>
      <td class="cell1">5</td>
      <td class="cell2">10</td>
    </tr>
    <tr>
      <td class="cell0">Milk</td>
      <td class="cell1">7</td>
      <td class="cell2">5</td>
    </tr>
    <tr>
      <td class="cell0">Bread</td>
      <td class="cell1">8</td>
      <td class="cell2">15</td>
    </tr>
  <!-- ... and so on! -->
  </tbody>
</table>

私がやりたいことは次のとおりです。
金額が最小金額よりも小さい場合は、金額の背景を赤にします。問題は、授業が繰り返されることです。だから私はただ言うことはできません:

if (parseInt($(".cell1").text()) < parseInt($(".cell2").text())) {
    $(".cell1").addClass("red");
}
4

2 に答える 2

0

なぜループをしないのですか?

$('.cell1').each(function() {
  if ( parseInt($(this).text()) < parseInt($(this).siblings(".cell2").text()) ) {
    $(this).addClass("red");
  }
})
于 2012-04-03T08:16:39.027 に答える
0

filter次の方法を使用します。

$('.cell1').filter(function() {
    return parseInt($(this).text()) < parseInt($(this).next('.cell2').text());
}).addClass('red');

jsFiddleを参照してください

于 2012-04-03T08:16:47.113 に答える