2017-04-30 86 views
2

我試圖使用Sweet Alert庫進行警報。 我試圖集成用於刪除項目的確認提醒的代碼,但是當我點擊刪除項目的按鈕時,這些工作不起作用。該對話框不顯示。顯示甜蜜警報對話框時出錯

代碼以前整合甜警報:

$(".delete-link").click(function() { 
    var id = $(this).attr("id"); 
    var del_id = id; 
    var parent = $(this).parent("td").parent("tr"); 
    if (confirm('Sure to Delete ID no = ' + del_id)) { 
     $.post('delete.php', { 'del_id': del_id }, function(data) { 
      parent.fadeOut('slow'); 
     }); 
    } 
    return false; 
}); 

代碼整合甜警報:

$(".delete-link").click(function() { 
     var id = $(this).attr("id"); 
     var del_id = id; 
     var parent = $(this).parent("td").parent("tr"); 
    }); 

    swal({ 
      title: "Are you sure you want to delete?", 
      text: "Sure to Delete ID no = " + del_id, 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#DD6B55", 
      confirmButtonText: "Yes", 
      closeOnConfirm: false 
     }, 
     function() { 
      $.post('delete.php', { 'del_id': del_id }, function(data) { 
       parent.fadeOut('slow'); 
      }); 
     }); 
    return false; 

}); 
+0

您是否在控制檯中發現錯誤? –

+0

不,我thibk有代碼的問題,但我現在沒有 – marte

回答

0

我認爲有代碼中的語法錯誤。試試這個,看看它是否有效[我沒有在我的側面測試過這個代碼]。如果它不起作用,請告訴我

$(".delete-link").click(function() { 
var id = $(this).attr("id"); 
var del_id = id; 
var parent = $(this).parent("td").parent("tr"); 

swal({ 
    title: "Are you sure you want to delete?", 
    text: "Sure to Delete ID no = " + del_id, 
    type: "warning", 
    showCancelButton: true, 
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Yes", 
    cancelButtonText: "No", 
    closeOnConfirm: true, 
    closeOnCancel: true 
}, function(isConfirm) { 
    $.post('delete.php', {'del_id':del_id}, function(data) { 
     parent.fadeOut('slow'); 
    }); 
}); 
return false; 
}); 
+0

完美的作品,謝謝:) – marte