简体   繁体   中英

Auto sum HTML table Column like we always do in Excel

I have one page which have one html table and the last column of the table has numeric value .

My doubt is , when we fill some numeric values in Excel column and If we select those columns together it will tell the sum of the total columns .

I want to do the same in HTML Table column. Is this possible to do ?

If It is possible can someone help me in this?

Can Someone help me how to do this... I googled everywhere I don't know how to do..

Get the last column cells, extract the number, sum.

 const sum = Array.from(document.querySelectorAll('td:last-of-type')). map(x => parseFloat(x.textContent)).reduce((x, y) => x + y); console.log(sum); 
 <table> <tr> <td>Foo</td> <td>3</td> </tr> <tr> <td>Bar</td> <td>4</td> </tr> </table> 

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