drqrdkfue521903877 2014-05-16 22:52
浏览 65
已采纳

HTML列总和

This may not be possible at all, but I thought I'd ask. Can I sum an HTML table column to get a total? For example take the screen shot below and total the hours where the in/out is equal to "2400-Orchard."?

enter image description here

I'm new to this stuff, so any suggestions would be great.

  • 写回答

1条回答 默认 最新

  • dougu1990 2014-05-16 23:15
    关注

    Yes it is possible using Javascript.

    Here is link to a working fiddle example.

    There are three divs, each with the same class and containing a unique value.

    <div class="cell">10</div>
    <div class="cell">20</div>
    <div class="cell">30</div>
    

    jQuery is used to select all the elements with the class "cell" and then get the text, convert it to a number (an integer in this case) and sum the values.

    var sum=0
    
    $(".cell").each(function(i) {
       sum = sum + parseInt($(this).text());
    });
    
    console.log(sum)
    

    The final sum is printed to the browser console.

    Edit:

    Here is an edited fiddle where the sum is added to the webpage using jQuery's append function.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘