我已关注table
,并希望将sum
子表input
放入parent
td
输入
<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>
感谢。
答案 0 :(得分:0)
您的代码非常模糊,但我认为这正是您所寻找的:
$(".gridrow2 td input").onkeyup(function() {
var sum = 0;
$(".gridrow2 :input").each(function() {
sum += $(this).val();
});
$("#gvSPActivities_gvBenefic_0_txtMaleBenefic_0").val(sum);
});
它将“父<td>
输入”的值更改为三个子输入的总和。我想。
答案 1 :(得分:0)
var result = 0;
$('table > td.gridrow2 > table > td').each(function() {
result += parseInt($(this).find('input.numeric').val());
});
$('td.gridrow2 > td:eq(2) > input[name="gvSPActivities$ctl02$TextVal3"]').val(result);
答案 2 :(得分:0)
我不知道您何时想要更新总数,但您可以使用此代码。
$('.gridrow2').each(function(){
var total = 0;
$(this).find('table > .numeric').each(function(){
total += this.value;
});
$(this).find('.total').val(total);
});