2016-02-09 52 views
2

我想替換標準確認對話框。 我的javascript函數在這裏我如何使用甜蜜警報進行確認?

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"); 
    }); 
} 

我如何使用gridview的模板列按鈕甜蜜的警報確認功能?

<asp:TemplateField ItemStyle-Width="60" HeaderText="Delete">  
    <ItemTemplate>   
     <asp:LinkButton ID="lbDeleteUser" Runat="server" OnClientClick="checkDelete();" CommandName="Delete">Delete</asp:LinkButton>  
    </ItemTemplate> 
</asp:TemplateField> 

斯坦達特確認功能在這裏

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

斯坦達特確認功能捉迷藏。但甜蜜的警報確認功能未運行。請幫助

這是非標準確認

enter image description here

Plase幫助。

+0

由於JavaScript中沒有「等待」,因此不可能自定義警報/確認並讓它返回一個值。您必須取消點擊操作並觸發JavaScript代碼的點擊/提交。 – epascarello

+0

我使用http://alertifyjs.com/一直在工作 – delueg

+0

我怎麼可以用sweetalert?請幫忙。 –

回答

2

使用此代碼,它會幫助你

swal({ 
      title: "Are you sure?", 
      text: "You will not be able to recover this imaginary file.", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#F44336", 
      confirmButtonText: "Yes, Sure !", 
      closeOnConfirm: true 
     }, function() { 

         swal({ 
          title: "Message", 
          text: 'Imaginary file deleted.', 
          type: "success" 
         }); }); 
0

不知道你的問題是怎麼回事,到目前爲止,但這裏是我的醜陋的解決方案。

 function confirmBeforePostback(obj) { 
      var res = $(obj).attr('onclick').split(';'); 

      if (res.length > 1) { 
       swal({ 
         title: "Are you sure?", 
         text: "The will delete your record, are you sure?", 
         showCancelButton: true, 
         closeOnConfirm: true, 
         closeOnCancel: true 
        }, 
        function (isConfirm) { 
         if (isConfirm) { 
          eval(res[1]); 
         } 
        }); 
      } 
      return false; 
     } 

在asp.net中,將代碼添加到onclick屬性中,如下面的示例。

後面的代碼:

((Button)e.Row.Cells[5].Controls[2]).Attributes["onclick"] = "if(!confirmBeforePostback(this)) return false;"; 

或ASPX:

<ItemTemplate>   
    <asp:LinkButton ID="lbDeleteUser" Runat="server" OnClientClick="confirmBeforePostback(this);" CommandName="Delete">Delete</asp:LinkButton>  
</ItemTemplate> 
0

萬一有人需要幫助,將來這裏是我用來實現這個的代碼段。

swal({ 
      title: '', 
      text: "Are you sure you want to delete selected record(s) ?", 
      type: 'question', 
      showCancelButton: true, 
      confirmButtonColor: '#3085d6', 
      cancelButtonColor: '#d33', 
      cancelButtonText: '<i class="fa fa-times"></i> @Resources.No', 
      confirmButtonText: '<i class="fa fa-check"></i> @Resources.Yes' 
     }).then(function() { 
      // loop on selected rows and remove them using jquery datatable method. 

      // display sweet alert 
      swal(
     { 
      title: "", 
      text: "Record Deleted", 
      type: "success", 
      allowOutsideClick: "true" 
     }); 

     }) 

快樂編碼!

相關問題