簡體   English   中英

Sweet Alert確認對話框在響應之前消失了嗎?

[英]Sweet Alert confirm dialog disappears before response?

我對Sweet Aler確認對話框有疑問。 當我單擊刪除圖標時,Sweet Alert對話框顯示的時間少於一秒鍾,然后消失並刪除該元素。 換句話說,我沒有機會單擊“刪除”或“取消”。 如何停止此對話框讓我選擇一個選項?

<a href="insert.php?delete=20"><i class="fa fa-trash-o fa-2x pull-right trashbin"></i></a>
---
<script type="text/javascript">
    document.querySelector('i.trashbin').onclick = function(event){

        swal({
            title: "Are you sure?",
            text: "You will not be able to recover this imaginary file!",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: '#DD6B55',
            confirmButtonText: 'Yes, delete it!',
            cancelButtonText: "No, cancel plx!",
            closeOnConfirm: false,
            closeOnCancel: false

        },

        function(isConfirm){
        if (isConfirm){
            swal("Deleted!", "Your imaginary file has been deleted.", "success");
        } else {
            swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
        });
    };
</script>

嘗試添加event.preventDefault(); 后:

document.querySelector('i.trashbin').onclick = function(event) {

您必須將'a'標記中的'src'值替換為'#',並將'delete = 20'傳遞給函數。 然后在該函數中,如果用戶單擊“是”,則重定向到使用傳遞給它的參數指定的頁面。 這解決了我的問題。 希望對您也有幫助。

** 編輯 **

<a href="#"><i class="fa fa-trash-o fa-2x pull-right trashbin"></i></a>
    ---
    <script type="text/javascript">
document.querySelector('i.trashbin').onclick = function () {
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: '#DD6B55',
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: "No, cancel plx!",
        closeOnConfirm: false,
        closeOnCancel: false
    }).then(function () {
        swal({timer: 1000, title: "Deleted!", type: "success"});
        setTimeout(function goAndDel() {
            window.location.assign("insert.php?delete=20");
        }, 1000);
    });
}
    </script>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM