我遇到了一些問題,看起來應該很容易處理JQuery。基本上我在我的頁面上有一張桌子。表格中的每一行都有一個複選框和一個單元格。我正在嘗試編寫一個遍歷每行的函數,並檢查該複選框是否被選中。如果是這樣,它會將金額加到我的總額中,以便我可以將其顯示在我的頁面底部。出於某種原因,我無法找到我的複選框。以下是頁面上的html。找到單個jquery後裔
<div class="BillAccordian">
<h3><A href="#">Past Due Bills - Total $ 1047.62 </A></h3>
<div>
<table style="background-color:Red">
<tr>
<td>
<input class="RowSelector" id="BillInfo_PastDueBills_0__Selected" name="BillInfo.PastDueBills[0].Selected" type="checkbox" value="true" />
<input name="BillInfo.PastDueBills[0].Selected" type="hidden" value="false" />
</td>
<td>
RE
</td>
<td>
334
</td>
<td>
1047.62
</td>
<td>
Bill Number 20121
</td>
</tr>
</table>
</div>
</div>
這裏是我使用的是現在要努力完成的jQuery腳本這個
$('input.RowSelector').click(function() {
var sum = 0;
alert("1");
// we want to sum up the values of all input.sum elements that are in the same tr
// as this one
$('tr').each(function (e) {
var val;
alert($(this).find(".RowSelector")[0].is(':checked'));
if ($(this).closest("input.RowSelector").val() == true) {
alert("3");
// val = parsefloat($(i).find(".BillAmount").val());
//
// if (isNaN(val) || val === undefined) {
// return;
}
// sum += val;
});
// $(this).find('#SelectedTotal').val(formatDollar(sum));
});
});
很多它是現在監守我只是tyring獲得選擇的保持註釋掉我需要繼續。在函數中使用警報我什麼也得不到。我認爲它不喜歡我所追求的[0],但用它找到沒有找到的東西。我確實檢查了我的$ this.html以確保我有正確的元素,並且它確實返回了整個表格行中的複選框,所以我很困惑這一點。有人能告訴我我錯過了什麼嗎?
感謝