繁体   English   中英

带确认和取消按钮的计时器

[英]Timer with confirm and cancel button

我是一个甜蜜警报的菜鸟。 是否可以创建一个带有确认按钮,取消和计时器的甜蜜警报提示。

逻辑是,如果未确认警报,计时器将自动执行与取消相同的功能。 我已经尝试并卡住了。 即使警报已确认,计时器仍在计时并调用取消功能。

sweetAlert({
    title: 'Stay in fullscreen',
    text: "You will be logged out in 10 seconds or if you leave the fullscreen!",
    type: 'warning',
    showCancelButton: true,
    confirmButtonColor: '#3085d6',
    cancelButtonColor: '#ff0000',
    confirmButtonText: 'Go fullscreen!',
    cancelButtonText: 'Leave this page!',
    confirmButtonClass: 'btn btn-success',
    cancelButtonClass: 'btn btn-warning',
    closeOnConfirm: 'true',
    timer:'10000',
    buttonsStyling: false
},function(isConfirm) {
    if (isConfirm) {
        return launchIntoFullscreen(document.documentElement) // timer still still counting
    } else {
        return Redirect() 
    }
}).then(function () {
    swal(
        window.alert('teest')
    )
}, function (dismiss) {
    // dismiss can be 'cancel', 'overlay',
    // 'close', and 'timer'
    if (dismiss === 'timer') {
        return Redirect()
    }
})

检查isConfirm参数是否为null可以告诉您回调是否已由计时器完成初始化。

swal({
    title: "Auto close alert!",
    text: "I will close in 2 seconds.",
    timer: 2000,
    showConfirmButton: true,
    showCancelButton: true
  }, 
  function(isConfirm) {
    if (isConfirm === null || isConfirm == false)
      cancelFunction();
    else
      confirmFunction();
  }
);

据我所知,这种行为没有记录在案,但我相信这是资料来源相关内容

 swal({ title: "Auto close alert!", text: "I will close in 2 seconds.", timer: 2000, showConfirmButton: true, showCancelButton: true }, function(isConfirm) { if (isConfirm === null || isConfirm == false) cancelFunction(); else confirmFunction(); } ); 

上面的代码仍然执行cancelFunction(); 我在ConfirmFunction之前添加一行。

 if (isConfirm !=null && isConfirm != false) { closeInSeconds = Number.MAX_VALUE/1000; // this line extends timer time document.documentElement); } else { Redirect(); } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM