我有一个动态生成的表,看起来像这样:
<table id="mytable">
<thead>
<tr>
<td>col1</td>
<td>col2</td>
<td>col3</td>
</tr>
</thead>
<tbody>
<tr>
<td>col1</td>
<td class="col2">1</td>
<td class="col3">2</td>
</tr>
<tr>
<td>col1</td>
<td class="col2">7</td>
<td class="col3">4</td>
</tr>
<tr>
<td>col1</td>
<td class="col2">col2</td>
<td class="col3">col3</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>Totals</td>
<td id="col2total"></td>
<td id="col3total"></td>
</tr>
</tfoot>
</table>
如何获得td
s 中具有类的值col2
的总和并将总和添加到td
id col2total
?由于此表是动态生成的,我不知道tr
在tbody
.