0

我有以下内容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>

谢谢。

4

3 回答 3

0

我不知道您何时要更新总数,但您可以使用此代码。

$('.gridrow2').each(function(){
    var total = 0;
    $(this).find('table > .numeric').each(function(){
        total += this.value;
    });

    $(this).find('.total').val(total);
});
于 2012-05-11T14:16:53.680 回答
0

您的代码非常模糊,但我认为这就是您要寻找的内容:

$(".gridrow2 td input").onkeyup(function() {
    var sum = 0;

    $(".gridrow2 :input").each(function() {
        sum += $(this).val();
    });

    $("#gvSPActivities_gvBenefic_0_txtMaleBenefic_0").val(sum);
});

它将“父<td>输入”的值更改为三个子输入的总和。我认为。

于 2012-05-11T14:13:33.903 回答
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);
于 2012-05-11T14:14:54.600 回答