我正在尝试制作此代码
var cbEarned = (parseInt(spending1) * parseFloat(cashBack1 / 100)) + (parseInt(spending2) * parseFloat(cashBack2 / 100)) + (parseInt(spending3) * parseFloat(cashBack3 / 100)) + (parseInt(everyThingElse) * parseFloat(everyThingCashBack / 100));
进入一个带有变量的循环花费[i] 和cashBack[i] 以便我可以缩短代码。它基本上是采用“添加更多”框并将字段添加到表中,并且需要抓取支出和现金返还,这可能是无限数量的字段。
这是我添加另一个功能
$(document).ready(function() {
var i = 1;
var count = 1;
$("#addCC").on("click", function() {
for (var i = 1; i <= 1; i += 1) {
$("#last").after('<tr><td>Choose a spending category <select id="spending' + i + '"><option value="">Spending Category</option></select></td><td class="calc-result-value">$ <input type="text" class="spending" id="spending_' + i + '"></td></tr><tr><td>What was your % cash back?</td><td class="calc-result-value">% <input type="text" class="cashBack" id="cashback_' + i + '"></td></tr>');
count += 1;
};
//Check to see if the user has more than 10 cards, if true, throw error!
if (count >= 10) {
alert("You have exceeded the amount of cards allowed which is 10!");
}
});
});
我希望我能正确解释这一点,这是第一次在这里发帖。