【问题标题】:Delete Confirmation in Client Side在客户端删除确认
【发布时间】:2014-04-12 09:19:55
【问题描述】:

在我的 Ajax 函数中有一个表格,其中有一个删除按钮。它正在工作但我想做当有人单击该删除按钮时,它需要询问确认对话框。我知道我们可以很容易地使用 OnClientClick ="return Confirm('Do you want to delete?') but here has been onClick,我该怎么做?

我的 Ajax 函数

 html += '<td>' + '<input type="button" value="Delete" onclick="deleteUploadFile(this,' + value.Id + ')">' + '</td>';

删除上传文件函数

function deleteUploadFile(element, id) {

         debugger;
         var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 

         $.ajax({
             url: url,
             type: "POST",
             data: JSON.stringify({ id: id }),
             dataType: "json",
             contentType: "application/json; charset=utf-8",
             success: function (Result) {
                 /*on success*/
                 $(element).parents('tr:first').remove();
             },
             error: function (e, x) {
                 //alert(x.ResponseText);
             }
         });
         }

【问题讨论】:

    标签: c# jquery asp.net ajax


    【解决方案1】:

    在你的函数中写下你的confirm

    function deleteUploadFile(element, id) {
    
         debugger;
         var url = '<%= ResolveUrl("/WebMethods.aspx/RemoveUploadedFile") %>'; 
    
         if(confirm('Deleting file. Are you sure?')) {
             $.ajax({
                 url: url,
                 type: "POST",
                 data: JSON.stringify({ id: id }),
                 dataType: "json",
                 contentType: "application/json; charset=utf-8",
                 success: function (Result) {
                     /*on success*/
                     $(element).parents('tr:first').remove();
                 },
                 error: function (e, x) {
                     //alert(x.ResponseText);
                 }
             });
         }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-19
      • 1970-01-01
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多