显示加载值的总数

Showing total of loaded values

本文关键字:加载 显示      更新时间:2023-09-26

嗨,我有列出某些销售值的表格。加载销售后,我想显示所有值的总和。现在它工作正常,但我必须更改一些值,它将显示总数。我还想在加载表单时显示总数。

           <form id="sales" action="" >                 
                <table class="salesTable" border="1" cellpadding="0" cellspacing="0">
                    <tbody>
                        {{#each items}}
                 <tr class="">
                     <td><input type="abd" name="{{=id}}" id="{{=id}}" value='{{=sales}}'  onchange="updateTotal(this.form)" /></td>                                               
                 </tr>        
                <tr>
                    <td style="font:bold">Total</td>
                    <td><input type="abd" name="sum" onfocus="this.blur()" readyonly  value=""/>         </td>
                </tr>
                    </tbody>
                </table>
            </form>

jquery函数是

function updateTotal(formObj) {
            var total = 0;
            total += parseInt(formObj.s1011.value, 10)
            total += parseInt(formObj.s1018.value, 10)
            total += parseInt(formObj.s1019.value, 10)         
            formObj.sum.value = total
        }

请让我知道如何更改它,以便在表单引导时它也将显示值的总和。谢谢

您可以在 DOM 加载并准备就绪时调用该函数。

例如,使用 jQuery:

$(function() { // This is executed when DOM is ready
    var form = $("#sales")[0]; // get the form's DOM node
    updateTotal(form); // call the function on it
});