2016-02-25 33 views
1
swal({title: "Sure ?", text: "Your form will be submitted", confirmButtonText: "Ok", 
showConfirmButton:true, showCancelButton: true, cancelButtonText: "No", type:"warning", closeOnConfirm: false, 
        closeOnCancel: false }, 
         function(isConfirm) { 
                 if (isConfirm) { 
                     swal({ 
                         title: 'Confirm!', 
                         text: 'Successfully Submitted!', 
                         type: 'success' 
                     }, function() { 
             console.log("Inside Function"); 
             $scope.applyleave("ok"); 


            }); 

                } else { 
swal("Cancelled", "Your application not submitted :)", "error"); 
           return false; 
                } 
            });  

碼流應繼續只在點擊確定,但它的執行沒有任何用戶執行Sweetalert不是等待用戶的動作,並用代碼進入

我提交表單從HTML這個JS,但我想阻止確認框並等待用戶操作並允許下面的代碼只在用戶按下時執行Ok

回答

0

不幸的是,這是javascript事件處理的本質。

爲了達到正常彈出的效果,只需在用戶在函數中響應時包裝需要運行的東西,然後在isConfirm函數中調用它。

正常彈出:

if (confirm("ORLY?")) { 
    console.log("YO!"); 
} 
else { 
    console.log("AWW!"); 
} 

console.log("KTHXBAI!"); 

SwaI位:

swal({ title: "ORLY?" }, 
    function(isConfirm) { 
     if (confirm("ORLY?")) { 
      console.log("YO!"); 
     } 
     else { 
      console.log("AWW!"); 
     } 

     finally(); 
     // you can also write codes directly here 
    }); 

function finally() { 
    console.log("KTHXBAI!"); 
}