如何使用javascript计算一列中gridview的文本框总和

问题描述:

我想使用javaScript计算gridview单列中文本框的总和。

当任何文本框的值发生变化时,将自动计算新值...



我试过这个剧本



I want to calculate sum of textboxes in single column of gridview using javaScript.
When value of any textbox changes the value will be automatically calculated with new one...

I tried the script

function CalculateTotals() {
           alert("dfhg");
           var grid = document.getElementById("rptExpense");
           var txt = document.getElementById("txtVFareTotal");
           alert(txt.value);
           for (var i = 0; i < 6; i++) {
               var val = grid.rows[i].columns[3].getElementById("txtexpense");
               alert(val.value);
           }







Plz help




Plz help

嘿Sumit,



您可以使用易于使用且需要编写较少代码行的jquery。在文本框中使用任何类如'Amount',并在jquery选择器中使用该类。



Hey Sumit,

You can use jquery which is easy to use and need to write less lines of code. Use any class like 'Amount' on text boxes and use that class in jquery selector.

function CalculateTotals() {
           
         var total=0;


' 。金额')。每个( function (){
total + = parseFloat
('.Amount').each(function(){ total+=parseFloat(


this )。val());
});
(this).val()); });