0

I know that it has been asked hundreds of times, but I can't find a way to get the previous td - probably because I'm a jquery beginner.

Here is my code:

findOverdue = function () {
  $("tbody").find("tr").each(function () {
    var paymentDate = $(this).find('td.paymentDate').text();
    var paymentDateTest = $(this).find('td.paymentDate').prev('td').text();
    var currentDate = $(this).find('td.currentDate').text();
    var isInitial = $(this).find('td.isIntial').text();
    var monthlyInstalment = $(this).find('td.monthlyInst').text();
    var penaltySize = $(this).find('td.penaltyPercent').text();
    var lastUpdated = $(this).find('td.lastUpdated').text();

    console.log("paymentDateTest: " + paymentDateTest);
  });
};

Now I'm trying to get the previous td value into the paymentDateTest variable without luck. I have tried few combinations without success. The console log is showing nothing. I know that I'm missing something really smal, but I'm not able to spot it.

EDIT:

HTML table:

<table class="dataTable" id="repaymentShedule">
            <thead>
                <tr>
                    <th>1</th>
                    <th>2</th>
                    <th>3</th>
                    <th>3</th>
                    <th>4</th>
                    <th>5</th>
                    <th>6</th>
                    <th>7</th>
                    <th>8</th>
                    <th>9</th>
                    <th style="display: none;">10</th>
                    <th style="display: none;">11</th>
                    <th>12</th>
                </tr>
            </thead>
            <tbody data-bind="foreach: creditDetails">
                <tr>
                    <td class="paymentDate" data-bind="text: dateOfPayment"></td>
                    <td class="startBalance" data-bind="text: beginingBalance"></td>                        
                    <td class="monthlyInt" data-bind="text: monthlyInterest"></td>
                    <td class="principal"><input data-bind="value: princpalPayment"></input></td>
                    <td class="monthlyInst" data-bind="text: monthlyInstallment"></td>
                    <td class="ammountToPay" data-bind="text: ammountToPay"></td>
                    <td class="remainingBalance" data-bind="text: endingBalance"></td>
                    <td class="paid"><input type="checkbox" data-bind="checked: isPaid, disable: isPaid, click: testFunc, value: true"></td> <!-- value: true moje da ne e nujno -->
                    <td class="currentDate" data-bind="text: currentDate"></td>
                    <td class="penalty" data-bind="text: penalty"></td>
                    <td class="isIntial" data-bind="text: isIntial" style="display: none;"></td>    
                    <td class="penaltyPercent" data-bind="text: penaltyPercent" style="display: none;"></td>    
                    <td class="lastUpdated" data-bind="text: lastUpdated"></td>             
                </tr>
            </tbody>
        </table>
4

3 回答 3

1

试试这个,如果你有 td

var paymentDateTest = $(this).find('td.paymentDate').prev().text();
于 2013-11-13T08:27:10.757 回答
1

我创建了快速jsfiddle,看起来像

 alert($('.prevDate').prev('td').text())

正在工作中。

于 2013-11-13T08:29:25.677 回答
0

我一直在寻找这个:

var paymentDateTest = $(this).prev().find('td.paymentDate').text();

非常感谢 Roko C. Buljan您帮助我!

于 2013-11-13T10:23:47.957 回答