您好我有一个javascript函数,应该是价格,我没有找到任何可以帮助我的jquery函数。 这是
背后的逻辑1 user to 4 will pay = 40 / user so 3users = 120
5 users to 9 will pay = 36/ user so 7 users = 268
10 users to 19 will pay = 32/user so 15 users = 564
20 users to 49 will pay 28/user so 40 users = 1220
50 users to 99 will pay 24/ user so 60users = 1860
100 users to infinite will pay 20/ user so 114 users = 3000
我需要某种功能才能做到这一点,我已经尝试使用多个数组并使用函数来检查数字是否在两个数字之间......
答案 0 :(得分:2)
我想我明白了,所以这样的事情可能有用:
function getTotal(num_users) {
var amount = 0;
if (num_users >= 100) {
amount = 20;
} else if (num_users >= 50) {
amount = 24;
} else if (num_users >= 20) {
amount = 28;
} else if (num_users >= 10) {
amount = 32;
} else if (num_users >= 5) {
amount = 36;
} else if (num_users >= 1) {
amount = 40;
}
return num_users*amount;
}
这是一个jsFiddle来演示: