首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >是否有一种方法可以使用sweetAlert.js来进行确认,而不是在onbeforeexit()期间使用方法中的标准

是否有一种方法可以使用sweetAlert.js来进行确认,而不是在onbeforeexit()期间使用方法中的标准
EN

Stack Overflow用户
提问于 2021-01-25 18:18:47
回答 1查看 134关注 0票数 0

我试图使用甜警报作为标准JavaScript确认对话框的替代品。我正在经历的问题是,当我返回承诺时,方法不会等待响应,它只是结束了巡演。

我希望看到这种方法接受承诺并等待响应。这个是可能的吗?

我希望在sweetAlert模式上单击no之后,我会像使用标准的javascript确认(‘)方法一样返回到旅游,如下所示

代码语言:javascript
复制
Introjs().onbeforeexit(function() {

        var alertText;

    if (instance.data.whatstep < steps.length){
        alertText = 'Are you sure you want to leave the tour early'
    } else {
        alertText = properties.alert_text
    }
    
    var r = confirm (alertText)
    if (r == true){
        console.log('exit')

        if ( instance.data.whatstep < steps.length ){
            console.log('leaving early')
            instance.triggerEvent("user_left_tour")

        } else {
            console.log('not leaving early')
            instance.triggerEvent("user_finished_tour")
        }
        
        return r
        
    } else {
        console.log('dont exit')
        return r
    }

});

下面是'onbeforeexit()‘代码,我是,试图使用不起作用的

代码语言:javascript
复制
    Introjs().onbeforeexit(function() {
     const r = async function confirm(message) {
        return swal({
            text: 'are you sure',
            buttons: true
        });
    }
        console.log(r())
        return r()
    
    }).start();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-01-25 18:24:51

我想这就是你想要的

代码语言:javascript
复制
Swal.fire({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  icon: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes, delete it!'
}).then((result) => {
  if (result.isConfirmed) {
    Swal.fire(
      'Deleted!',
      'Your file has been deleted.',
      'success'
    )
  }
}) 

这在SweetAlert 2中是可维护的。

下面是您要查找的相同链接的链接:"A确认对话框,其中一个函数附加于“确认”-button.

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65890255

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档