javascript - Sum TD in TABLE -
<table id="tab" border="1"> <tr> <td>one</td><td>123</td><td></td><td>32</td> </tr> <tr> <td>two</td><td>52</td><td></td><td>53</td> </tr> <tr> <td>three</td><td>234</td><td></td><td>56</td> </tr> </table> $('#tab').click(function(){ sum(); }) function sum(){ //???? }
how best method sum column second , fourth td , fill in third td each tr?
function sum(){ $("tr").each(function(){ var sum = parsefloat($(this).find("td:eq(1)").text()) + parsefloat($(this).find("td:eq(3)").text()); $(this).find("td:eq(2)").text(sum); }) }
here, have fiddle: http://jsfiddle.net/byf8c/10/
Comments
Post a Comment