JavaScriptconfirm()
アクションをアップグレードしてSweetAlertを使用しようとしています。現在、私のコードは次のようなものです:
<a href="/delete.php?id=100" onClick="return confirm('Are you sure ?');" >Delete</a>
これは、削除ページに移動する前に、ユーザーが確認するのを待ちます。SweetAlert のこの例を使用して、削除する前にユーザーに確認を求めたいと思います。
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");
}
});
私が試したことはすべて失敗しました。最初のアラートが表示されたとき、ページはアイテムを削除し、ユーザーがアラート ボタンをクリックする前に更新されました。ページがユーザーの入力を待つようにするにはどうすればよいですか?
どんな助けでも大歓迎です。