2016-10-21 9 views
0

確認ボタンに問題があります。 ボタンをクリックすると、上部に同じリンクが残っています コードを確認すると、リンクは 'www.website.com?'になりますが、window.location.href='?'は機能しません。JavaScript SweetAlert

\t function myfunction(){ 
 
\t \t swal({ 
 
\t \t title: 'Sweet Alert', 
 
\t \t html: true, 
 
\t \t type: "success", 
 
\t \t showConfirmButton:true, 
 
\t \t preConfirm: function(end) { 
 
\t \t \t \t window.location.href='?' 
 
\t \t } 
 
\t }); 
 
\t  
 
\t };
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.min.css" rel="stylesheet"/> 
 

 
<input type='button' onclick='myfunction()' value='Sweetalert'>

+0

preConfirm()が呼び出されていません。それはどこから来たのですか?私は甘美な文書でそれを見ることはできません。 – Kenji

+0

perConfirmは機能ではありません。それは甘いタラソウが来ているが、私はそれをする方法を知らなかった。 –

答えて

0

あなたはpreConfirmを持っていませんsweetalertのバージョンを使用しているので、その機能は、あなたのコード内で実行されることはありません。 あなたはpreConfirmを持っているフォークを必要とする:https://github.com/limonte/sweetalert2 preConfirmも、返される約束を期待する例を参照してください。https://limonte.github.io/sweetalert2/#ajax-request

function myfunction() { 
 
    swal({ 
 
     title: 'Sweet Alert', 
 
     html: true, 
 
     type: "success", 
 
     showConfirmButton: true, 
 
     preConfirm: function (end) { 
 
      $('#test').html('success'); 
 
      return new Promise(function (resolve, reject) { 
 
       resolve(); 
 
      }); 
 
     } 
 
    }); 
 

 
};
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/5.3.8/sweetalert2.min.js"></script> 
 
<link href="https://cdnjs.cloudflare.com/ajax/libs/limonte-sweetalert2/5.3.8/sweetalert2.min.css" rel="stylesheet"/> 
 

 
<input type='button' onclick='myfunction()' value='Sweetalert'> 
 
<div id="test"></div>

関連する問題