簡體   English   中英

如何使用Sweet Alert替換標准確認對話框?

[英]How to use Sweet Alert to replace standard confirm dialog?

我要替換標准的確認對話框。 我的javascript函數在MasterPage中。

function checkDelete() {
  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!", 
    closeOnConfirm: false 
  },function () { 
      swal("Deleted!", "Your imaginary file has been deleted.", "success"); 
  });
}

我想在內容頁面中調用checkDelete函數。如何在gridview templatefield按鈕中使用甜蜜警報?

<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">     
  <ItemTemplate>        
    <asp:LinkButton ID="lbDelete" Runat="server" OnClientClick=" return confirm('Are you sure?');" CommandName="Delete">Delete</asp:LinkButton>     
  </ItemTemplate>
</asp:TemplateField>
</Columns>

請幫忙。

由於javascript在母版頁中可用,因此它在當前頁中同樣可用(如果使用相同的母版)。 如下更改OnClientClick事件,它應該可以工作。

<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();" CommandName="Delete">Delete</asp:LinkButton>

更新資料

這就是我模擬您的項目所做的。

  • 創建了一個新的Web應用程序項目
  • Scripts文件夾中添加了甜蜜的警報腳本,css文件
  • </head>之前添加了HTML之類的參考

<link rel="stylesheet" href="Scripts/sweetalert.css"> <script src="Scripts/sweetalert.min.js"></script>

  • 添加了與</body>之前在主文件中提供的功能相同的javascript函數
  • 在default.aspx代碼中添加了以下幾行

<asp:LinkButton ID="lbDelete" Runat="server" OnClientClick="checkDelete();return false;" CommandName="Delete">Delete</asp:LinkButton>

這可以正確顯示甜蜜警報。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM