检测价格是否高于或低于200.00然后样式(此)表格行

时间:2016-04-21 03:04:32

标签: javascript jquery

注意这个问题对我之前提到的here问题非常敏感,但我似乎还是无法绕过它。

这是我目前的表结构:



<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>
<table class="table group-9569" width="100%">
  <tbody>
    <tr>
      <td class="order_id"  width="10%"><span class="orderId">9569</span></td>
      <td class="order_date"  width="13%">
        <span >2016-04-14 17:39:00</span>
      </td>
      <td class="order_name"  width="10%"><span >John Smith</span></td>
      <td class="order_paid"  width="5%">
        <span  class="total-cost-9569 orderPaid">¥81.28</span>
      </td>
      <td class="order_shipping"  width="13%">Shipping</td>
      <td class="order_status"  width="10%">
        <span  class="order-status-9569">Paid</span>
      </td>
      <td class="order_tracking"  width="10%"></td>
      <td class="new-msg-img-9569">
      </td>
    </tr>
  </tbody>
</table>

<table class="table group-9564" width="100%">
  <tbody>
    <tr>
      <td class="order_id"  width="10%"><span class="orderId">9564</span></td>
      <td class="order_date"  width="13%">
        <span >2016-04-14 17:24:10</span>
      </td>
      <td class="order_name"  width="10%"><span >Jane smith</span></td>
      <td class="order_paid"  width="5%">
        <span  class="total-cost-9568 orderPaid">¥209.69</span>
      </td>
      <td class="order_shipping"  width="13%">Shipping</td>
      <td class="order_status"  width="10%">
        <span  class="order-status-9568">Paid</span>
      </td>
      <td class="order_tracking"  width="10%"></td>
      <td class="new-msg-img-9568">
      </td>
    </tr>
  </tbody>
</table>
&#13;
&#13;
&#13;

我需要检测orderPaid是高于还是低于¥200.00然后样式this表格行

我知道可以将它转换为如下的javascript编号:

var orderPaid = $('.orderPaid').html();
var number = Number( orderPaid.replace(/[^0-9\.]+/g,""));

问题是当我每行只需要它们时会得到每个订单。

解决此问题的最佳方法是什么?如何通过定价将每一行独立区分为样式?

1 个答案:

答案 0 :(得分:3)

你迭代

$('.orderPaid').each(function(index, element) {

    var content = $(element).text();
    var number  = +content.replace(/[^0-9\.]+/g,"");
    console.log(number)

    if ( number > 200 ) {
        $(element).css('background', '#ff9b9b');
    }

});