【问题标题】:Sweetalert getting closed automaticallySweetalert 自动关闭
【发布时间】:2023-01-17 21:12:53
【问题描述】:

我在我的项目中使用了 sweet alert 但它在几秒钟内就关闭了

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>

<script>
        function deleteContact(cid){
            
            swal({
                  title: "Are you sure?",
                  text: "You want to delete this contact?",
                  icon: "warning",
                  buttons: true,
                  dangerMode: true,
                  timer: 5000, 
                })
                .then((willDelete) => {
                  if (willDelete) {
                    /* swal("Poof! Your imaginary file has been deleted!", {
                      icon: "success",
                    }); */
                    window.location="/user/delete/"+cid;
                  } else {
                    swal("Your contact is safe!");
                  }
                });
        }   
    </script>
---------------------------------------------------------------------------------------
deleteContact() function is being called here in below delete button-

<a href="" th:onclick="|deleteContact(${c.cId})|"><i class="fa-solid fa-trash text-danger" title="Delete"></i></a>

【问题讨论】:

  • 您的配置上有一个 5 秒的计时器,是这个意思吗?

标签: javascript html spring-boot sweetalert


【解决方案1】:

从您的 swal 配置中删除“计时器:5000”

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    • 1970-01-01
    • 2012-02-21
    • 2015-02-14
    • 2011-01-15
    • 2017-08-04
    相关资源
    最近更新 更多