在确认警报框中显示订单

时间:2015-10-25 22:39:22

标签: javascript html function

所以我得到了这个功能:

function displayTotal() {
                var r = confirm("Are you sure you want to place this order?");
                if (r == true) {
                    x = "Your order has been placed!" + document.forms["drinkList"].reset();
                } else {
                    x = ""
                }
            }

我要做的是获取所有订购商品的总成本,以及每件商品的数量,数量和价格。

我正在使用此功能,以获得特定饮品的总量。

var totalEstimate = 0;
var blackCost = 0;

function calcBlack() {
                totalEstimate -= blackCost;
                blackCost = document.forms.quant1.value * 0.99;
                totalEstimate += blackCost;
                document.drinkList.order.value = "$" + totalEstimate;
            }

我试过了:

function displayTotal() {
                var r = confirm("Are you sure you want to place this order?" + calcBlack());
                if (r == true) {
                    x = "Your order has been placed!" + document.forms["drinkList"].reset();
                } else {
                    x = ""
                }
            }

但那并没有显示任何东西。有人能指出我正确的方向吗?感谢。

我在这里打电话给displayTotal()

<input type="button" value="Order" name="order" onclick="displayTotal()" />

1 个答案:

答案 0 :(得分:1)

calcBlack不会返回任何内容,您需要修改它以返回要在confirm提醒框中显示的数据。

function calcBlack() {
    totalEstimate -= blackCost;
    blackCost = document.forms.quant1.value * 0.99;
    totalEstimate += blackCost;
    document.drinkList.order.value = "$" + totalEstimate;

    return totalEstimate;
}