jQuery总结ASP转发器中的文本框

时间:2019-02-18 19:53:24

标签: jquery repeater

我有4个文本框(1-4)和一个文本框5,这是我的总数。我想做的是将textbox(1-4)汇总起来。我遇到的问题是,移至下一行时似乎无法将变量重置为零。

<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
        <asp:HiddenField ID="HiddenFieldID" runat="server" Value='<%# Eval("SortID") %>' />

        <div style="float: left; text-align: left; padding-left: 5px;">
            <%# Eval("Product") + " ( " + Eval("Info") + " Count by " + "<b>" + Eval("CountBy") + "</b>" + " )" %>
            <br />
            <span style="display: inline-block; text-align: center">
                <asp:Label ID="Label2" runat="server" Text='<%# Eval("Location1") %>' AssociatedControlID="TextBox1" Font-Size="9px"></asp:Label>
                <br />
               <%-- <input id="TextBox1" type="text"  runat="server" Width="100px" CssClass="txbox" Text='<%# Eval("Count1") %>' onchange="javascript:rowTot(this);" />--%>
                <asp:TextBox ID="TextBox1" runat="server" Width="100px" CssClass="txbox" Text='<%# Eval("Count1") %>'  AutoCompleteType="Disabled" TextMode="Phone" class="t1"></asp:TextBox>
            </span>
            <span style="display: inline-block; text-align: center" >
                <asp:Label ID="Label3" runat="server" Text='<%# Eval("Location2") %>'  AssociatedControlID="TextBox2" Font-Size="9px">Cooler</asp:Label>
                <br />
               <asp:TextBox ID="TextBox2" runat="server" Width="100px"  CssClass="txbox" Text='<%# Eval("Count2") %>' AutoCompleteType="Disabled" TextMode="Phone" class="t2"></asp:TextBox>

            </span>
            <span style="display: inline-block; text-align: center">
                <asp:Label ID="Label4" runat="server" Text='<%# Eval("Location3") %>'  AssociatedControlID="TextBox3" Font-Size="9px"></asp:Label>
                <br />
                <asp:TextBox ID="TextBox3" runat="server" Width="100px" CssClass="txbox" Text='<%# Eval("Count3") %>' AutoCompleteType="Disabled" TextMode="Phone" class="t3"></asp:TextBox>
            </span>
            <span style="display: inline-block; text-align: center">
                <asp:Label ID="Label5" runat="server" Text='<%# Eval("Location4") %>'  AssociatedControlID="TextBox4" Font-Size="9px"></asp:Label>
                <br />
                <asp:TextBox ID="TextBox4" runat="server" Width="100px" CssClass="txbox" Text='<%# Eval("Count4") %>' AutoCompleteType="Disabled" TextMode="Phone" class="t4" ></asp:TextBox>
            </span>

            <asp:TextBox ID="TextBox5" runat="server" Width="100px" CssClass="txbox" ReadOnly="true" placeholder="Total" Text='<%# Eval("TotalCount") %>'></asp:TextBox>

        </div>

    </ItemTemplate>
</asp:Repeater>


<script src="../lib/jquery-3.3.1.min.js"></script>     
<script type="text/javascript">


    $(document).ready(function () {  

        var  value1 = 0, value2 = 0, value3 = 0, value4 = 0, tot = 0;


       $('[id*=Repeater1_TextBox1]').on('change', function () {
            var id = $(this).attr('id');
            value2 = $('#' + id).val();
            tot = (parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4));
            $(this).parent().siblings('input[id*=TextBox5]').val(tot);

        });

        $('[id*=Repeater1_TextBox2]').on('change', function () {
            var id = $(this).attr('id');
            value2 = $('#' + id).val();
            tot = (parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4));
            $(this).parent().siblings('input[id*=TextBox5]').val(tot);

        });

        $('input[id*=TextBox3]').on('change', function () {
            var id = $(this).attr('id');
            value3 = $('#' + id).val();
            tot = (parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4));
            $(this).parent().siblings('input[id*=TextBox5]').val(tot);


        });
        $('input[id*=TextBox4]').on('change', function () {
            var id = $(this).attr('id');
            value4 = $('#' + id).val();
            tot = (parseInt(value1) + parseInt(value2) + parseInt(value3) + parseInt(value4));
            $(this).parent().siblings('input[id*=TextBox5]').val(tot);

        });  



      });


</script>

0 个答案:

没有答案