アイテム(ワイン)のIDと注文したボトルの数量の2つの引数を取る関数があります。
順序は動的jqueryテーブルに組み込まれます。
ロジックは、ユーザーが3本以上のボトルを購入した場合に割引が適用され、ワインの割引を示す行が追加されるというものです。値を3以上に変更してから、値を3未満に下げる場合は、割引を示す行を削除します。
なぜこれが機能しないのですか?アラートが発生しているので、remove()行のエラーだと思います。
function UpdateWineDiscount(id, qty) {
// Does discount row already exist?
if ($("#trTable tr > td:contains('D" + id + "')").length) {
// If discount row exists and qty is now below 3, remove it
if (qty < 3) {
$("D" + id).remove();
alert("remove");
};
} else {
// Is qty >= 3?
if (qty >= 3) {
// Add discount row
var newRow = $("<tr id='D" + id + "' style='color:red'> <td class='drinkID' style='display:none'>D" + id + "</td> <td class='drinkName'>Wine Discount</td> <td></td> <td></td> <td></td> <td></td> <td class='drinkTotal'>-1</td> </tr>");
$("#trTable").append(newRow);
} else {
// Update discount value
};
};
}