簡體   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