无法让Jquery脚本忽略html表中的最后两行

问题描述 投票:0回答:2

我有一个动态增长的表,然后是Jquery脚本,用于写入paypal用于每个的'name'属性。我使用每个<tr>(++ r)的递增器为我写的每个paypal字段添加一个数字增量,例如amount_1,amount_2等。

该脚本运行良好,直到我添加了“交付成本”行,该行不应包含在将“名称”属性分配给其余表行的例程中。

此外,脚本从底线开始运行并移动顶部,我希望它从顶部开始并运行到底部 - 我如何实现这一目标?

html表:

<table id="quote">
    <th>Sign type</th>
    <th>Size</th>
    <th>Qty</th>
    <th>Unit price</th>
    <th>Subtotal</th>
    <th>Cancel</th>
    <tr class="checkoutOptions">
        <td>
            <input class="finalSign" type="hidden" value="123" />Sign name</td>
        <td>40 X 40</td>
        <td>
            <input maxlength="2" class="finalQty" value="5" />
        </td>
        <td class="unitFocus">
            <input class="finalUnitPrice" type="hidden" value="50" />$50</td>
        <td class="subtotal">'+$XX</td>
        <td></td>
    </tr>
    <tr class="checkoutOptions">
        <td>
            <input class="finalSign" type="hidden" value="123" />Sign name</td>
        <td>40 X 40</td>
        <td>
            <input maxlength="2" class="finalQty" value="5" />
        </td>
        <td class="unitFocus">
            <input class="finalUnitPrice" type="hidden" value="50" />$50</td>
        <td class="subtotal">'+$XX</td>
        <td></td>
    </tr>
    <tr class="checkoutOptions">
        <td>
            <input class="finalSign" type="hidden" value="123" />Sign name</td>
        <td>40 X 40</td>
        <td>
            <input maxlength="2" class="finalQty" value="5" />
        </td>
        <td class="unitFocus">
            <input class="finalUnitPrice" type="hidden" value="50" />$50</td>
        <td class="subtotal">'+$XX</td>
        <td></td>
    </tr>
    <tr class="deliveryCost">
        <td><span class="italic">Delivery cost for all items</span>
        </td>
        <td></td>
        <td></td>
        <td></td>
        <td class="subtotal">S$0</td>
        <td></td>
    </tr>
    <tr id="total">
        <td>Grand total:</td>
        <td colspan="4">
            <input id="pprice" type="hidden" name="amount" maxlength="5" value="" />S$0</td>
        <td>
            <input id="buy_now" type="image" src="/img/buy_button.png" name="submit" alt="PayPal . The safer, easier way to pay online." onclick="optionsFormsReset()" />
        </td>
    </tr>
</table>

和Javascript / jquery:

function paypalPasser() {
    var r = 0;
    $("#quote tr:last td:not(:first,:last)").html(function (c) {
        $(this).parent().prevAll().find("td:nth-child(" + (c + 1) + ")").each(function () {
            ++r;
            $(this).find('.finalSign').attr("name", "item_name_" + r + "");
        });
    });
    //reiterate r(reset to 0) & function here for each paypal field
    //on0
    r = 0;
    $("#quote tr:last td:not(:first,:last)").html(function (c) {
        $(this).parent().prevAll().find("td:nth-child(" + (c + 2) + ")").each(function () {
            ++r;
            $(this).find('.finalSize').attr("name", "on0");
        });
    });
    //quantity_
    r = 0;
    $("#quote tr:last td:not(:first,:last)").html(function (c) {
        $(this).parent().prevAll().find("td:nth-child(" + (c + 3) + ")").each(function () {
            ++r;
            $(this).find('.finalQty').attr("name", "quantity_" + r + "");
        });
    });
    //amount_
    r = 0;
    $("#quote tr:last td:not(:first,:last)").html(function (c) {
        $(this).parent().prevAll().find("td:nth-child(" + (c + 4) + ")").each(function () {
            ++r;
            $(this).find('.finalUnitPrice').attr("name", "amount_" + r + "");
        });
    });
}
jquery html-table rows
2个回答
© www.soinside.com 2019 - 2024. All rights reserved.