带JQuery的Sum表列

2024-09-20 22:22:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一张所有销售额的表格,上面有客户的姓名、日期和销售价格。在

我有一个允许用户搜索表的脚本,但我也希望有一个脚本返回表中可见的所有销售价格的总和。在

例如,如果用户搜索T.Toe,那么脚本将返回T.Toe所有销售价格的总和。在

代码:

<table class="well table table-condensed small" id="academy">
  <tr>
   <td colspan="3">
    <input type="text" id="search_academy" placeholder="  quick search" autocomplete="off">
   </td>
   <td><input type='text' style="width: 30px;" id='sum'></td>
  </tr>
  {% for sale in academy|sort(attribute="sale_date", reverse=True) %}
   {% if sale.price > 0 %}
    <tr class="success">
     {% else %}
    <tr class="danger">
   {% endif %}
  <th>{{ sale.sale_date.strftime('%d-%m-%Y') }}</th>
  {% if sale.client %}
   <th>{{ sale.client }}</th>
  {% else %}
   <th>{{ sale.concept }}</th>
  {% endif %}
  <th>{{ sale.club }}</th>
  <th class="prices">{{ sale.price }}</th>
  </tr>
  {% endfor %}
 </table>

JQuery用于在表上进行实时搜索,并返回搜索单元格的总和:

编辑:

感谢@pointy和@user4621032,当前的脚本是:

^{pr2}$

我将parseInt更改为parseFloat以保留1位小数。在

这将返回.prices类列中所有单元格的总和。不过,我希望脚本只返回.prices单元格的总和,这些单元格是通过用户搜索在#search_academy中返回的。在

谢谢!在


Tags: 用户脚本idsearchtablesaletrclass

热门问题