我有用戶使用jquery和ajax刪除函數。當用戶點擊Delete
彈出窗口出現並詢問他是否確定按鈕Yes
和No
。問題是腳本在點擊Delete
時被執行並且用戶被刪除。用戶點擊No
並不重要。Jquery modal with confirmation is submited before user confirmation
我使用這個jQuery插件確認: https://myclabs.github.io/jquery.confirm/
這是jQuery的部分
$(document).ready(function() {
$('.delete').click(function() {
var parent = $(this).closest('.header-profile');
$.ajax({
type: 'get',
url: 'misc/friendRemove.php',
data: 'ajax=1&delete=' + $(this).attr('id'),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
},
success: function()
{
parent.fadeOut('slow', function() {$(this).remove();});
}
});
});
$('.delete').confirm({
text: "Are you sure?",
title: "Please confirm",
confirmButton: "Yes",
cancelButton: "No",
post: true,
confirmButtonClass: "btn-danger",
cancelButtonClass: "btn-default",
dialogClass: "modal-dialog modal-lg"
});
});
而且按鈕
<a href="" class="delete" id="'.$row['id'].'"><i class="fa fa-times pull-right"></i></a>
將您在'$ .click'中定義的函數放入$ .confirm中的'confirm:'選項 - 根據您鏈接到的頁面上的文檔 - 以及不要讓按鈕成爲''標籤 - 還有其他可能需要編碼的副作用 - 使用'
看到(非)工作片段。另外,您似乎在可以清理的''中有一個PHP殘餘。 –
我試過這個,但是沒有彈出。 –