javascript - 如何在sweetalert中选择两个选项并根据该选项采取行动?

标签 javascript php jquery css sweetalert

我有一个 Sweetalert,只需要 OkCancle。如果ok它会根据该执行选项。

我需要两个选项:付款不付款。如果用户选择With Payment,它会要求用户输入金额并将其发送到另一个页面。

我当前的 order.list.js 页面如下所示

function completeOrder(orderID) {
  var obj = {
    order: order,
    page: page,
    customer: $("#customers_" + from).val(),

    sdate: $("#sdate_" + from).val(),
    edate: $("#edate_" + from).val(),
    Status: Status
  };

  swal({
    title: "Are you sure?",
    text: "You want to complete this order Without Payment !!",
    icon: "warning",
    buttons: true,
    dangerMode: true,
  }).then((willDelete) => {
    if (willDelete) {
      $.ajax({
        url: "process/order-process.php",
        type: "POST",
        data: {
          orderID: orderID,
          status: "Completed",
          payment: "Not Paid"
        },
        beforeSend: function() {},
        success: function(response) {
          if (response.indexOf("success") >= 0) {
            swal("Good job! Your order has been completed!", {
              icon: "success",
            });
            getResult(true, 'process/order-list.php', "POST", JSON.stringify(obj), from);
          } else {
            swal("Error!", "Something went wrong!", "error");
          }
        }
      });
    } else {}
  });
}

最佳答案

你有没有尝试过下面这样的事情

swal("Place the order?", {
    title: "Are you sure?",
    text: "You want to complete this order Without Payment !!",
    icon: "warning",
    buttons: {
        withPayment: "With Payment",
        withOutPayment: "With out Payment",
    }
})
.then((value) => {
    switch (value) {

        case "withPayment":
            // Proceed with payment
            break;

        case "withOutPayment":
            // Proceed without payment
            break;
    }
});

关于javascript - 如何在sweetalert中选择两个选项并根据该选项采取行动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59069310/

相关文章:

javascript - 一个连接上可以有多个 "categories"吗?

javascript - react 链接不起作用

php - 从用户输入中获取字母数字字符串的安全方法? (没有 preg_replace)

php - 从 PHP 链接访问 JavaScript 变量

javascript - JQGrid 有两个垂直滚动条(左和右)

javascript - jQuery offsetparent 也返回非定位父级

javascript - 具有交替行和行号的文本区域

javascript - 如何在没有 npm 的情况下使用 Vue.js 元素?

php - 如何 : Displayed image file name different than actual filename on server

javascript - 在 JQuery/Backbone 中,如何重写每个 AJAX 请求以添加附加参数?