同样的问题if if()语句会导致它停止工作。
我正在为我的广告代理商构建自定义订单表单,用户从表单复选框中选择他们想要的商品,下面的小计/订单摘要表会相应更新。客户需要至少获得1125美元的基本位置,而四个次要位置是可选的,并且是450美元。如果客户决定获得额外的[s],那么贩运成本也会上升(每个75美元)。
一切正常,直到我达到最高金额,然后表格没有正确更新。
更新完整问题: http://jsfiddle.net/joelslevy21/5v8Ltkxf/3/
更新的脚本:
if ( totalFinal == "3,330" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("4");
$('#subTotalCompanion').text("$1,800");
$('#quantityTrafficking').text("5");
$('#subTotalTrafficking').text("$375");
} else if ( totalFinal == "2,775" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("3");
$('#subTotalCompanion').text("$1,350");
$('#quantityTrafficking').text("4");
$('#subTotalTrafficking').text("$300");
} else if ( totalFinal == "2,250" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("2");
$('#subTotalCompanion').text("$900");
$('#quantityTrafficking').text("3");
$('#subTotalTrafficking').text("$225");
} else if ( totalFinal == "1,725" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("1");
$('#subTotalCompanion').text("$450");
$('#quantityTrafficking').text("2");
$('#subTotalTrafficking').text("$150");
} else {
$('#companion').css("display","none");
$('#quantityTrafficking').text("1");
$('#subTotalTrafficking').text("$75");
}
答案 0 :(得分:1)
由于Trafficking
/ 2
/ {{1},您的$80
始终保持在if
/ else
,因为您将其设置为if
/ else
} / if ( totalFinal == "805" ) {
$('#companion').css("display","block");
$('#quantityTrafficking').text("2"); // Sets to 2
$('#subTotalTrafficking').text("$80"); // Sets to $80
} else {
$('#companion').css("display","none");
$('#quantityTrafficking').text("1"); // Ignored due to other else
$('#subTotalTrafficking').text("$40"); // Ignored due to other else
}
if ( totalFinal == "1,095" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("2");
$('#subTotalCompanion').text("$500");
$('#quantityTrafficking').text("3"); // Sets to 3
$('#subTotalTrafficking').text("$120"); // Sets to $120
} else {
$('#quantityTrafficking').text("2"); // Sets to 2, as it overwrites other else
$('#subTotalTrafficking').text("$80"); // Sets to $80, as it overwrites other else
$('#quantityCompanion').text("1");
$('#subTotalCompanion').text("$250");
}
阻止
if
您想要的是elseif
/ else
/ if ( totalFinal == "1,095" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("2");
$('#subTotalCompanion').text("$500");
$('#quantityTrafficking').text("3");
$('#subTotalTrafficking').text("$120");
} else if ( totalFinal == "805" ) {
$('#companion').css("display","block");
$('#quantityCompanion').text("1");
$('#subTotalCompanion').text("$250");
$('#quantityTrafficking').text("2");
$('#subTotalTrafficking').text("$80");
} else {
$('#companion').css("display","none");
$('#quantityTrafficking').text("1");
$('#subTotalTrafficking').text("$40");
}
阻止
{{1}}