如何在 sweetalert 中选择两个选项并根据该选项采取行动?
How to take two option in sweetalert and take action according to that option?
我有一个只需要 Ok
和 Cancle
的 Sweetalert。如果ok
它根据那个执行选项。
我需要两个选项:With Payment
和 Without Payment
。如果用户选择 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;
}
});
我有一个只需要 Ok
和 Cancle
的 Sweetalert。如果ok
它根据那个执行选项。
我需要两个选项:With Payment
和 Without Payment
。如果用户选择 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;
}
});