-2
テーブルセルの各テキストボックスの値を合計するのに問題があります。Jqueryはテキストボックス値の各セルを合計しますか?
<asp:Table ID="table101" runat="server" CssClass="table100">
<asp:TableRow>
<asp:TableCell>Item 1 </asp:TableCell>
<asp:TableCell>:</asp:TableCell>
<asp:TableCell>
<cus:cusTextBox ID="txtCDesc0" runat="server" Action="View" ></cus:cusTextBox>
</asp:TableCell>
<asp:TableCell>Cost: RM
<cus:cusTextBox ID="txtCCost0" runat="server" Action="Edit" class="cost" CssClass="inputTextM" OnKeyUp="return calculateTotalCost()"></cus:cusTextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Item 2</asp:TableCell>
<asp:TableCell>:</asp:TableCell>
<asp:TableCell>
<cus:cusTextBox ID="txtCDesc1" runat="server" Action="View" ></cus:cusTextBox>
</asp:TableCell>
<asp:TableCell>Cost: RM
<cus:cusTextBox ID="txtCCost1" runat="server" Action="Edit" class="cost" CssClass="inputTextM" OnKeyUp="return calculateTotalCost()"></cus:cusTextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Item 3</asp:TableCell>
<asp:TableCell>:</asp:TableCell>
<asp:TableCell>
<cus:cusTextBox ID="txtCDesc2" runat="server" Action="View" ></cus:cusTextBox>
</asp:TableCell>
<asp:TableCell>Cost: RM
<cus:cusTextBox ID="txtCCost2" runat="server" Action="Edit" class="cost" CssClass="inputTextM" OnKeyUp="return calculateTotalCost()"></cus:cusTextBox>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>Item 4 </asp:TableCell>
<asp:TableCell>:</asp:TableCell>
<asp:TableCell>
<cus:cusTextBox ID="txtCDesc3" runat="server" Action="View" ></cus:cusTextBox>
</asp:TableCell>
<asp:TableCell>Cost: RM
<cus:cusTextBox ID="txtCCost3" runat="server" Action="Edit" class="cost" CssClass="inputTextM" OnKeyUp="return calculateTotalCost()"></cus:cusTextBox>
</asp:TableCell>
</asp:TableRow>
私のjQueryコード:
//--Calculate total cost--
function calculateTotalCost() {
$('#<%=table101.ClientID %> tr').each(function() {
var total;
cost = parseFloat($(this).find("td").eq(3).find('input').val()).toFixed(2);
total += cost;**//error**
alert(total);
});
}
//**Calculate total cost**
私はテキストボックスの値のそれぞれを合計することはできませんテキストボックス値の各セルを取得することができるけど、ここで私が書いたコードです。助けてください。これは緊急の問題です。ありがとう:)
エラーは何ですか? 'total'を0に初期化しようとしましたか? 'cost'がローカル変数であることを確認しようとしましたか? –