Javascript 如何在不使用承诺的情况下重写swal提示符

Javascript 如何在不使用承诺的情况下重写swal提示符,javascript,sweetalert2,Javascript,Sweetalert2,我想在删除项目之前为我的警报提供一个提示选项。但是它在IE中不起作用。我如何避免使用这个承诺(.then()) swal的示例如下: swal({ title: "Are you sure?", text: "Once deleted, you will not be able to recover this imaginary file!", icon: "warning", buttons: true, dangerMode: true, }) .then((willDe

我想在删除项目之前为我的警报提供一个提示选项。但是它在IE中不起作用。我如何避免使用这个承诺(
.then()

swal的示例如下:

swal({
  title: "Are you sure?",
  text: "Once deleted, you will not be able to recover this imaginary file!",
  icon: "warning",
  buttons: true,
  dangerMode: true,
})
.then((willDelete) => {
  if (willDelete) {
    swal("Poof! Your imaginary file has been deleted!", {
      icon: "success",
    });
  } else {
    swal("Your imaginary file is safe!");
  }
});

假设swal的其余部分在IE上工作(您检查过了吗?),那么您需要:

  • 添加一个
    Promise
    polyfill,其中有许多很容易获得,并且

  • 不要使用箭头函数,因为IE不支持箭头函数

  • 例如,对于Promise polyfill,这是IE的有效代码:

    swal({
      title: "Are you sure?",
      text: "Once deleted, you will not be able to recover this imaginary file!",
      icon: "warning",
      buttons: true,
      dangerMode: true,
    })
    .then(function(willDelete) { // <=== Only change is here
      if (willDelete) {
        swal("Poof! Your imaginary file has been deleted!", {
          icon: "success",
        });
      } else {
        swal("Your imaginary file is safe!");
      }
    });
    
    swal({
    标题:“你确定吗?”,
    text:“一旦删除,您将无法恢复此虚拟文件!”,
    图标:“警告”,
    按钮:是的,
    丹格莫德:没错,
    })
    .then(函数(将删除){//