使用JQuery把总和家长TD [英] Putting sum in Parent td using JQuery

查看:109
本文介绍了使用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);
});

这篇关于使用JQuery把总和家长TD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆