标签: sweetalert2

SweetAlert2在计时器后执行功能

我在这里做错了什么?

swal({
    title: "Done.",
    text: "Labels Printed.",
    timer: 1000,
    type: "success",
    showConfirmButton: false

}).then(function () {

    alert('done');

});
Run Code Online (Sandbox Code Playgroud)

警报未触发,我是否需要以某种方式捕获“计时器”?(警报只是一个示例,我实际上是在这里清除表单。)

另外,我该如何摆脱textLabels:1未捕获(承诺)计时器错误?

我在用 .done()

有人可以为SweetAlert2添加标签吗?我没有做到这一点的声誉。

米克

如果我不希望以后发生任何事情,该怎么办?:

swal({
    title: "Error.",
    text: "Authorisation Failed.",
    timer: 1000,
    type: "error",
    showConfirmButton: false
}).then(
    function() {}

 )
Run Code Online (Sandbox Code Playgroud)

像这样?:

}).then(
        function() {},
        function() {}
       )
Run Code Online (Sandbox Code Playgroud)

jquery sweetalert sweetalert2

2
推荐指数
1
解决办法
2977
查看次数

Sweet Alert 2 和 javascript:如何制作一个甜蜜警报按钮,点击后将我发送到某个网页

到目前为止我的代码:

swal({ 
    title: 'Successfully Registered!', 
    text: "Do you want to go to the Log In page?", 
    type: 'success', 
    showCancelButton: true, 
    confirmButtonColor: '#3085d6', 
    cancelButtonColor: '#d33', 
    confirmButtonText: 'Yes, send me there!' 
    }, 
    function(){ 
       window.location.href= "http://example.com"; 
    }
); 
Run Code Online (Sandbox Code Playgroud)

由于某种原因,window.location.href 不起作用,我尝试只使用location.href 和if(isConfirm) 等
。我该怎么办?
JSFiddle:https ://jsfiddle.net/2dz868kd/

html javascript jquery sweetalert sweetalert2

2
推荐指数
1
解决办法
5350
查看次数

使用SweetAlert2显示加载警报,而无需交互

现在我有以下代码:

swal({
     title: 'Loading cars from data base',
     showLoaderOnConfirm: true,
     preConfirm: () => {
       return this.carsSvc.getCars().then((cars: ICar[]) => {
               this.setData(cars);
               resolve();
            });
    }
});
Run Code Online (Sandbox Code Playgroud)

此代码显示警报,我必须按“确认”,然后显示加载图标并在加载完成时关闭。我只需要执行此操作的最后一部分,因此我不想在开始加载之前先确认加载。我希望加载在警报打开时开始,并在加载完成后自动关闭。SweetAlert2有可能吗?

promise typescript sweetalert sweetalert2

2
推荐指数
3
解决办法
9104
查看次数

如何在模态内使用sweetalert2?

我正在使用sweetalert2,最新版本的sweetalert,我如何在模型中调用sweetalert?警报出现但它实际上被模式阻止了,这是我得到的结果。结果

它实际上被模态挡住了,我能做些什么让它在前面?谢谢你!

        swal({
        title: "Are you sure?",

        type: "warning",
        confirmButtonText:"Yes",
        confirmButtonColor:"#18a689",
        cancelButtonText:"No",
        showCancelButton: true,
        showLoaderOnConfirm: true
    }).then( function () {
        $.ajax({
            url: [[@{/jobDetails/remove}]],
        type: "POST",
            data:{jobId:id,masterId:masterListId},
        success: function (result) {
            if (result=="success"){
                refreshJobDetails(masterListId)
                reWriteMainTable();
            }
        },
        error: function (thrownError) {

        }
    });
    })
Run Code Online (Sandbox Code Playgroud)

jquery bootstrap-modal sweetalert sweetalert2

2
推荐指数
2
解决办法
1万
查看次数

SweetAlert2 取消按钮无法正常工作

我的SweetAlert2 中有一个 Yes 和 No 按钮。当我单击“否”时,它会发布一个方法,但我只希望它关闭 SweetAlert。

这是我写的代码:

   $('.js-update-details-click').click(function () {

        var Id = Number($(this).data('result-id'));

        swal({
            title: 'Are you sure you want to ask the User to update their details?',
            type: 'warning',
            showCancelButton: true,
            closeOnConfirm: false,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: 'Yes',
            cancelButtonText: 'No',
            confirmButtonClass: 'btn btn-success btn-full-width mar-bot-5',
            cancelButtonClass: 'btn btn-danger btn-full-width mar-bot-5',
            buttonsStyling: false
        })
            .then(function (isconfirm) {
                if (isconfirm) {
                    $.ajax({
                        type: "POST",
                        url: '/Common/ComposeUpdateDetailsEmail',
                        data: { ReplyType: 'CleanUpdateDetails', Id: Id },
                        success: function (data) …
Run Code Online (Sandbox Code Playgroud)

sweetalert sweetalert2

2
推荐指数
1
解决办法
7831
查看次数

如何在JavaScript中显示SweetAlert

如何在此JavaScript代码中显示SweetAlert?

function removeReg(del_reg) {
  if (confirm("Are you sure you want to delete? \n the reg name : " + del_reg)) {
    // Code goes here
  }
}
Run Code Online (Sandbox Code Playgroud)

我只想在if条件下调用SweetAlert ,即在SweetAlert中,我需要显示消息"Are you sure you want to delete?".

javascript sweetalert sweetalert2

2
推荐指数
1
解决办法
1245
查看次数

如何从按钮中删除类并在sweetalert2中添加自定义类?

我正在使用 sweetalert2 插件。它工作正常,但现在我想删除按钮类并添加我自己的类。

class=swal2-confirm swal2-styled但我需要class=swal2-confirm btn btn-success

任何解决方案表示赞赏!

 Swal.fire({
        title: 'Are you sure?',
        text: 'You will not be able to recover this imaginary file!',
        type: 'warning',
        showCancelButton: true,
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: 'No, keep it,'
    }).then((result) => {
        if (result.value) {
            Swal.fire(
                'Deleted!',
                'Your imaginary file has been deleted.',
                'success'
            )

        } else if (result.dismiss === Swal.DismissReason.cancel) {
            Swal.fire(
                'Cancelled',
                'Your imaginary file is safe :)',
                'error'
            )
        }
    })
Run Code Online (Sandbox Code Playgroud)

javascript jquery sweetalert2

2
推荐指数
2
解决办法
5575
查看次数

向 Sweet Alert 2 添加一个类

此问题已针对 sweetalert 1 向 sweetalert 添加类提出

现在我的问题是,如何在 sweetalert2 中添加自定义类?

className: "new_class" 对我不起作用。

sweetalert2

2
推荐指数
1
解决办法
1万
查看次数

在 Firefox 的引导模式下,Sweet Alert 中的文本框无法聚焦

我有一个包含文本框的 sweetalert 框。sweetalert 在引导模式框中打开。在 Firefox 中,我尝试单击文本框,但它没有获得焦点。

这是我的甜蜜警报代码:

swal(
        {
            title:              "Create New Design",
            input:              "text",
            showCancelButton:   true,
            inputPlaceholder:   "Title",
            preConfirm: function(input)
            {
                // code to validate the input
            }
        });
Run Code Online (Sandbox Code Playgroud)

这是屏幕截图:

在此输入图像描述

javascript firefox bootstrap-modal sweetalert sweetalert2

1
推荐指数
1
解决办法
3429
查看次数

ajax完成后如何使Sweet alert自动关闭?

我正在使用甜蜜警报,但如果 ajax 的请求完成,我想让它自动关闭

swal({
  title: "Are you sure?",
  text: "You are choosing order by custom search",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Confirm",
  closeOnConfirm: false,
  timer: **AUTO WITH AJAX??**
},
Run Code Online (Sandbox Code Playgroud)

我正在添加一个变量

var dones = $(document).ajaxComplete(function(){
                            swal.close()
                        });
Run Code Online (Sandbox Code Playgroud)

并像这样制作 swal

swal({
  title: "Are you sure?",
  text: "You are choosing order by custom search",
  type: "warning",
  showCancelButton: true,
  confirmButtonColor: "#DD6B55",
  confirmButtonText: "Confirm",
  **timer: dones,**
  closeOnConfirm: false
},
Run Code Online (Sandbox Code Playgroud)

但仍然不像我预期的那样

php ajax sweetalert sweetalert2

1
推荐指数
1
解决办法
6202
查看次数