简体   繁体   中英

How to calculate the values inside the TR using jQuery

I have a scenario I need to calculate the values inside the tr using jQuery.

I have attached the below screenshot of the page where I need to calculate the working days of an employee and show the day count in NWD(NO of working days)

在此处输入图片说明

Thanks in advance

Since you haven't posted your code, here is how you would do it for a particular table row :)

  <table id="tableid">
    <tr id="first">
      <td>1</td>
      <td>1</td>
      <td>1</td>
    </tr>
  </table>

  <script>
    var sum = 0;
    $("#tableid tr#first td").each(function(){
      var temp = parseInt($(this).html());
      sum += isNaN(temp)?0:temp;
    })
    console.log(sum)
  </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM