我试图创建一个票据预订表单,根据用户输入动态更新定价。根据表单选择计算多个座位价格?
到目前为止,我已经能够工作的是根据用户选择的内容(基于特定标准)的组合过滤选项。
我需要做的下一件事是以某种方式让表格根据选定的数量和票据类型计算个人座位价格,然后将它们累加为总价。
我在创建一个关联数组用于定义基于一定的标准票每种类型的价格做出了尝试:
//price of seating
function getPrices(day, time) {
var day = $('#whichDay').val(); // gets day value
var time = $('#whichSession').val(); //gets time value
var prices = new Array(); // creates the array
if (day == 'mon' || day == 'tue' || time == '1pm') {
prices["SA"] = 12;
prices["SP"] = 10;
prices["SC"] = 8;
prices["FA"] = 25;
prices["FC"] = 20;
prices["B1"] = 20;
prices["B2"] = 20;
prices["B3"] = 20;
} else {
prices["SA"] = 18;
prices["SP"] = 15;
prices["SC"] = 12;
prices["FA"] = 30;
prices["FC"] = 25;
prices["B1"] = 30;
prices["B2"] = 30;
prices["B3"] = 30;
}
return prices;
}
的问题是,我不能确定在哪里何去何从或如果我已经创建了适当的表格,以便它可以进行这种计算。
有很多有,所以我已经创建工作提琴为你们玩弄:提前http://jsfiddle.net/qtsxkgrw/2/
非常感谢!
你有没有考虑过使用淘汰赛?请检查:http://knockoutjs.com/examples/cartEditor.html –