2015-07-18 4 views
1

Подтверждение My SweetAlert не ждет никаких действий. Подтверждающий флажок просто мигает, а затем действие будет выполнено. Что не так?SweetAlert не ждет подтверждения

<script type="text/javascript"> 
    function confirmDelete() { 
     swal({ 
      title: "Are you sure?", 
      text: "You will not be able to recover this imaginary file!", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#DD6B55", 
      confirmButtonText: "Delete", 
      cancelButtonText: "Cancel", 
      closeOnConfirm: false, 
      closeOnCancel: false 
     }); 
    } 
</script> 

<form onsubmit="confirmDelete()" action="index.php" method="post"> 
    <button type="submit" name="delete">Delete</button> 
</form> 

Также попробовал это. Такая же проблема ... окно просто мигает и действие выполняется.

<script type="text/javascript"> 
    function confirmDelete() { 
     swal({ 
      title: "Are you sure?", 
      text: "You will not be able to recover this imaginary file!", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#DD6B55", 
      confirmButtonText: "Delete", 
      cancelButtonText: "Cancel", 
      closeOnConfirm: false, 
      closeOnCancel: false 
     }, 
     function(isConfirm) { 
      if (isConfirm) { 
       document.deleteForm.submit(); 
      } 
     }); 
    } 
</script> 

<form id="deleteForm" action="index.php" method="post"> 
    <button onclick="confirmDelete()" type="input" name="delete">Delete</button> 
</form> 

ответ

0

У меня есть чувство, что это связано с освежающим страницы, потому что форма не мешает быть представлен как только ваш обратный вызов.

+0

Как насчет другого примера, который я добавил в свой пост. Там я использовал событие onclick вместо 'onsubmit'. – lingo

+0

@lingo: Это в основном то же самое. Форма будет отправлена. – Becojo