【问题标题】:Fire sweetalert toast from a sweetalert without closing it从 sweetalert 发射 sweetalert 吐司而不关闭它
【发布时间】:2019-05-24 13:36:29
【问题描述】:

我有一个项目管理系统,我使用一个sweetalert 弹出窗口作为每个项目的设置菜单,我想在设置更改时触发祝酒词,但这会导致菜单关闭。有没有办法在不使用其他库的情况下完成这项工作?

这是我尝试为 sweetalert 菜单运行的代码

var id = 65352;
Swal.fire({
      title: 'settings for project '+id,
      html:
        "<p>some setting</p>"+
        "<input class='toggle' id='setting' data-docid='"+id+"' type='checkbox' checked>",
        showCancelButton: true,
        showConfirmButton: false,
        cancelButtonText:  'close',
      onBeforeOpen: () => {
        const setting = $("#setting[data-docid="+id+"]");

        $(setting).on("change",function(){
            console.log($(this).attr("checked"));
            if($(this).attr("checked") == "checked"){
                $checked = 1;
            }else{
                $checked = 0;
            }
            $.parameters = {
                id: id,
                checked: $checked,
                type: "accept"
            }
            //using an api to communicate between client and server
            result = "TRUE"
            if(result.indexOf("TRUE") > -1){
                const Toast = Swal.mixin({ //when firing the toast, the first window closes automatically
                  toast: true,
                  position: 'top-end',
                  showConfirmButton: false,
                  timer: 3000
                });

                Toast.fire({
                  type: 'success',
                  title: 'changed the thingy successfully'
                })
            }else{
                const Toast = Swal.mixin({ //when firing the toast, the first window closes automatically
                  toast: true,
                  position: 'top-end',
                  showConfirmButton: false,
                  timer: 3000
                });

                Toast.fire({
                  type: 'error',
                  title: 'cant change the thingy'
                })
            }
        });

      }
    })
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8.11.5/dist/sweetalert2.all.min.js"></script>

【问题讨论】:

    标签: javascript sweetalert2


    【解决方案1】:

    不幸的是,reading this thread 这似乎是不可能的,因为吐司在某种程度上是一种模态......

    但是last comment 指出可以修改 Swal2 的代码;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-01-17
      • 2015-02-10
      • 2021-10-06
      • 1970-01-01
      • 1970-01-01
      • 2018-11-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多