2017-09-27 189 views
1

我已經使用SweetAlert庫在我的應用程序中顯示彈出窗口。這是我的代碼如何在SweetAlert彈出窗口中添加關閉按鈕

swal({ 
    title: "Are you sure?", 
    text: "Test message?", 
    type: "info", 
    showCancelButton: true, 
    focusConfirm: false, 
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Yes", 
    cancelButtonText: "No" 
}, function (isConfirm) {}) 

我需要在右上角添加一個關閉按鈕。基於文檔,關閉按鈕僅適用於SweetAlert2庫。

是否可以在SweetAlert1庫中添加關閉按鈕?

+1

看來你使用AngularJS。爲什麼不使用** ngSweetAlert **? https://github.com/oitozero/ngSweetAlert – Zooly

+0

我已經在我的應用程序中使用了sweetalert。我不能使用任何其他庫 –

+0

還有一個取消按鈕,它也可以用來關閉彈出 –

回答

2
swal({ 
title: "Are you sure?", 
text: "Test message?", 
type: "info", 
showCancelButton: true, 
focusConfirm: false, 
confirmButtonColor: "#DD6B55", 
confirmButtonText: "Yes", 
cancelButtonText: "No", 
showCloseButton: true, 

只需添加showCloseButton: true,這將顯示在彈出的右上角的關閉X圖標。

來源:參見SweetAlerts2 Docs

注「自定義HTML描述和按鈕ARIA標籤」例如,它是不是在SweetAlert1庫現在已不建議使用,我建議使用SweetAlert2。