簡體   English   中英

使用Jquery Sweet Alert實施Confirm()

[英]Implementing confirm() with Jquery Sweet Alert

我想用著名的sweet alert插件在JavaScript上實現一個confirm() 但是以某種方式發出的甜蜜警報無法正常工作。

這是我的代碼:

function kendaraan(param) {
        if (swal({
                title: "Are you sure?",
                text: "You wanna leave this page?",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "Yes, Leave!",
                closeOnConfirm: false
              },
                function(){

                })
            ){
            switch (param) {
                case "ADD_KENDARAAN" :
                    $.ajax({
                        type: "POST",
                        url: "pages/lj_menu/vehicle/add_vehicle.php",
                        success: function (response, textStatus, jqXHR) {
                            $('#lj-mainpage').html(response);
                        }
                    });
                    break;
            }
        }
    }

所以我的意圖是當用戶單擊“ ADD KENDARAAN”時,它應該顯示甜蜜的警告確認,而當用戶單擊“是”然后執行ajax部分時。

if不必要,請不要使用。 根據文檔只實現你的switch內部anonymous functionsuccess如下:

function kendaraan(param) {
     swal({   
           title: "Are you sure?",
           text: "You wanna leave this page?",
           type: "warning",
           showCancelButton: true,
           confirmButtonColor: "#DD6B55",
           confirmButtonText: "Yes, Leave!",
           closeOnConfirm: false
     },
     function(){   
           switch (param) {
                case "ADD_KENDARAAN" :
                      $.ajax({
                            type: "POST",
                            url: "pages/lj_menu/vehicle/add_vehicle.php",
                            success: function (response, textStatus, jqXHR) 
                                     {
                                        $('#lj-mainpage').html(response); 
                                        swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
                                        //keep success message here if you wish to
                             }
                      });
                  break;
            }
     });
}

From the DOCS

暫無
暫無

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

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