-1

我正在尝试根据选择的数量来计算一个座位的成本,问题是第一个座位的成本与其他座位的成本不同。

第一 = 2250 额外座位收费 995

我的语法和计算应该是什么?

//seats variable

var costOfSeats;


//Calculate cost of seats and display cost of seats

$('#range--seats').on("change", function() {

if ($(this).val(1)) {
  costOfSeats == 2250;
} else {
  costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here
}

$('.output--seats').val("£" + costOfSeats);
}).trigger("change");
4

2 回答 2

1
var n = 3; //number of seats
var sum = 0;
var extraSeat = 995;
var seat = 2250;

if (n != 0) {
    sum = seat + ((n-1) * extraSeat)
}
于 2017-02-10T12:42:50.357 回答
0
if ($(this).val(1)) {
  costOfSeats == 2250;
} else {
  costOfSeats == costOfSeats + ($(this).val(-1) * 995);// problem here
}

您正在使用costOfSeats == costOfSeats, 而不是costOfSeats = costOfSeats. 您正在比较值而不是分配它们

于 2017-02-10T12:47:19.793 回答