我可以有多个Sweet Alert 2弹出窗口吗?

问题描述 投票:1回答:1

我的HTML / Javascript应用程序使用了我使用Sweet Alert 2创建的模式弹出窗口。我们称其为“ Alert1”

[Alert1使用的是自定义HTML,并且该HTML中有一个按钮,我想触发另一个甜蜜警报2模式弹出窗口,我们将其称为“ Alert2”

Alert2有两个选项。 “确认”或“取消”如果用户单击“取消”,我想返回Alert1。

这里有个问题:Alert1的自定义HTML是可编辑的,因此,我不能只是重新调用最初启动警报的代码,因为这会显示旧的HTML。

这是我尝试过的:

function clickButton(){ //This function will be attached to the button in Alert1
    var currentSwal = document.getElementById('swal2-content').innerHTML;
      swal({
      title: "Confirm 'Remove Script Page'",
      text:
        "Are you sure you want to remove this page from the script?",
      type: "warning",
      showConfirmButton: true,
      showCancelButton: true
    }).then(function(dismiss) {
      if (dismiss.dismiss == "cancel" || dismiss.dismiss == 'overlay') {
        swal.close;
        swal({
          html: currentSwal,
          showConfirmButton: false,
          customClass: 'swal-extra-wide',
          showCloseButton: true
        });
      } //end if
      else {
      //go ahead and delete the script page
      } //end else
    });
}//end function

我上面的解决方案不起作用。有点难以解释,但是从根本上讲,HTML代码已损坏,事情无法正常进行。

TLDR /我的问题:有没有办法让多个SweetAlert2警报出现? (即从alert1启动alert2,然后关闭alert2,将视图返回到alert1吗?

javascript html modal-dialog alert sweetalert2
1个回答
0
投票

是的,

var modals = [];


  modals.push({title: 'title Of Modal1', text: 'text1' });

  modals.push({title: 'title Of Modal2', text: 'text2' });

swal.queue(modals);

参考Question 38085851 Answer 1

© www.soinside.com 2019 - 2024. All rights reserved.