本文介绍了转发器文本框值的总和的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 亲爱的朋友们, 我需要转发器页脚中的Repeater文本框值的总和。我试过JQuery按键事件,它第一次执行正常..当我点击保存/取消按钮事件。值的总和不执行。如何解决... 谢谢&问候, Vivek .R 我尝试过: < script type = text / javascript> $( document )。ready( function (){ // 遍历每个文本框并添加keyup事件处理程序 $( 。clsTxtToCalculate)。each( function (){ $( this )。keyup( function (){ // 将总计初始化为0 var total = 0 ; $( 。clsTxtToCalculate)。each( function (){ // 仅当输入的文本为数字且大于0时才求和。 if (!isNaN( this .value)&& this .value.length!= 0 ){ total + = parseFloat ( this .value); } }); // 将总数分配给标签 // 。toFixed()方法将最终总和舍入为2位小数 $(' #<%= lblAcFees.ClientID%>')。html(total.toFixed( 2 )); }); }); }); < / script> < itemtemplate > < tr > < td style = display:none; > < asp:Label runat = server ID = lblFeesCode text =' <% #Eval( FeesCode)%>' / > < / td > < td > < asp:Label runat = server ID = lblFees text =' <% #Eval( 费用)%>' / > < / td > < td > < ; asp:TextBox ID = txtFeesAmt runat = server 宽度 = 100px 文本 = 0 onkeypress = return isNumberDotKey(event); CssClass = clsTxtToCalculate style = text -align:right; > < asp:RequiredFieldValidator ID = rfvFeesAmt runat = server ForeColor = 红色 controltovalidate = txtFeesAmt errormessage = * ValidationGroup = vg1 / > < / td > < / tr > < / itemtemplate > 解决方案 ( document )。ready( function (){ // 遍历每个文本框并添加keyup事件处理程序 ( 。clsTxtToCalcul吃)。each( function (){ (这个)。keyup( function (){ // 将总计初始化为0 var total = 0 Dear Friends,I need sum of Repeater textbox values in repeater footer. I have tried with JQuery key press event, it executed fine at first time.. When i click save/cancel button event. the sum of values is not execute. how to resolve...Thanks & regards,Vivek .RWhat I have tried:<script type="text/javascript"> $(document).ready(function () { //Iterate through each Textbox and add keyup event handler $(".clsTxtToCalculate").each(function () { $(this).keyup(function () { //Initialize total to 0 var total = 0; $(".clsTxtToCalculate").each(function () { // Sum only if the text entered is number and greater than 0 if (!isNaN(this.value) && this.value.length != 0) { total += parseFloat(this.value); } }); //Assign the total to label //.toFixed() method will roundoff the final sum to 2 decimal places $('#<%=lblAcFees.ClientID %>').html(total.toFixed(2)); }); }); }); </script><itemtemplate> <tr> <td style="display:none;"><asp:Label runat="server" ID="lblFeesCode" text='<%# Eval("FeesCode") %>' /> </td> <td><asp:Label runat="server" ID="lblFees" text='<%# Eval("Fees") %>' /></td> <td> <asp:TextBox ID="txtFeesAmt" runat="server" Width="100px" Text="0" onkeypress="return isNumberDotKey(event);" CssClass="clsTxtToCalculate" style="text-align:right;"> <asp:RequiredFieldValidator ID="rfvFeesAmt" runat="server" ForeColor="Red" controltovalidate="txtFeesAmt" errormessage="*" ValidationGroup="vg1" /> </td> </tr> </itemtemplate> 解决方案 (document).ready(function () { //Iterate through each Textbox and add keyup event handler(".clsTxtToCalculate").each(function () {(this).keyup(function () { //Initialize total to 0 var total = 0; 这篇关于转发器文本框值的总和的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-22 22:54
查看更多