使用JQuery把总和家长TD
问题描述:
我有以下表
,我想把子表输入
到之
父
D
输入
I have following table
and I want to put sum
of child table input
into parent
td
input
<table cellspacing="0" rules="all" border="1" id="gvSPActivities" style="border-collapse: collapse;">
<tr>
<th scope="col">
TextVal1
</th>
<th scope="col">
TextVal2
</th>
<th scope="col">
TextVal3
</th>
</tr>
<tr class="gridrow2">
<td>
<input name="gvSPActivities$ctl02$TextVal1" type="text" id="gvSPActivities_TextVal1_0"
class="numeric" style="width: 150px;" />
</td>
<td>
<input name="gvSPActivities$ctl02$TextVal2" type="text" id="gvSPActivities_TextVal2_0"
class="numeric" style="width: 150px;" />
</td>
<td>
<input name="gvSPActivities$ctl02$TextVal3" type="text" id="gvSPActivities_TextVal3_0"
class="total" style="width: 150px;" />
<table>
<tr>
<td>
<input name="gvSPActivities$ctl02$gvBenefic$ctl02$txtMaleBenefic" type="text" id="gvSPActivities_gvBenefic_0_txtMaleBenefic_0" class="numeric" style="width:100px;" />
</td><td>
<input name="gvSPActivities$ctl02$gvBenefic$ctl02$txtFemaleBenefic" type="text" id="gvSPActivities_gvBenefic_0_txtFemaleBenefic_0" class="numeric" style="width:100px;" />
</td>
</tr>
</table>
</td>
</tr>
</table>
感谢。
答
我不知道什么时候你要全部更新,但你可以使用这个code。
I don't know when do you want to update the total but you can use this code.
$('.gridrow2').each(function(){
var total = 0;
$(this).find('table > .numeric').each(function(){
total += this.value;
});
$(this).find('.total').val(total);
});