0
現在、このJavaScriptを使用して、asp:ラベルに表示されているテキストボックスを合計しています。asp:aspxページでJavaScriptを使用しているラベル
$(document).ready(function() {
//Iterate through each Textbox and add keyup event handler
$(".myTextBox0").each(function() {
$(this).keyup(function() {
//Initialize total to 0
var total = 0;
$(".myTextBox0").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
//.toFixed() method will roundoff the final sum to 2 decimal places
$('#<%=lblJobTotals0.ClientID %>').html(total.toFixed(2));
});
});
});
私は(別のラベルへの)すべての合計ラベルの総計に身を合計するすべての合計ラベルに同じことをどのように行うのですか?
私は唯一の結果として、lblTotalsAllが "0"に変更されたことを試しました。
$(document).ready(function() {
//Iterate through each Labels
var total = 0;
// all labels to sum have cssClass = .lblTotals
$(".lblTotals").each(function() {
// add to the total
var labelValue = $(this).text();
if (!isNaN(labelValue) && labelValue.length != 0) {
total += parseFloat(labelValue);
}
});
$('#<%=lblJobTotalsAll.ClientID %>').html(total.toFixed(2));
});
help @Davidに感謝します。私は成功なしで次のことを試みた。 { //各ラベルを繰り返し処理する var total = 0; //すべてのラベルにはcssClass = .lblTotalsがあります $( ".lblTotals")。each(function(){ 総 VAR labelValue = $(この)は.text()に追加//; をするif(!!ますisNaN(labelValue)&& labelValue.length = 0){ 合計+ = parseFloatは(labelValue);} } ); $( '#<%= lblJobTotalsAll.ClientID%>').html(total.toFixed(2)); }); – AhabLives
@AhabLives:コメントのコードはほとんど読めない。また、「成功しません」と定義します。どのように失敗しましたか? – David
私は元の質問を更新しました。希望が役立ちます。 - ありがとう。 – AhabLives