【问题标题】:How to use dialog-modal confirmation before deleting?删除前如何使用对话框模式确认?
【发布时间】:2010-10-27 07:31:36
【问题描述】:

这是我第一次使用 jQuery dialog_modal confirmation。 我想在删除 ajax 函数中的数据之前使用它。 我仍然很困惑如何正确放置这个脚本。

在使用此对话框之前,我有一些脚本,例如:

 $('#delete').click(function() {
          var params = $('#deletedata').serialize();
          $.ajax({
                   async  : false,
                   cache  : false,
                   data   : params,
                   success: function(res) {
                     //        oTable.fnReloadAjax();
                               $('#recline1').replaceWith("<div id='recline1'></div>");
                               $('#recmodel1').replaceWith("<div id='recmodel1'></div>");
                               $('#tabs').hide();
                               return this;
                               },
                   type   : "POST",
                   url    : "process1.php",
                   });
             return false;
        });

我希望如果单击delete,则会出现此对话框,然后如果我们选择delete at dialog,则删除过程会执行,但如果我们选择no,则所有打开的选项卡都会隐藏。


编辑

我这样试过,可以出现确认对话框:

$('#delete').click(function() {
              $('#dialog-confirm').dialog('open');
              var params = $('#deletedata').serialize();
              ....

我仍然对如何在模态确认中获取按钮 id 然后与 ajax 函数结合感到困惑?

【问题讨论】:

    标签: jquery ajax modal-dialog confirmation


    【解决方案1】:

    您可以在对话框初始化时将您的 ajax 函数放入按钮处理程序中。然后按照上面的描述打开。

    $('#dialog-confirm').dialog({
        autoOpen: false,
        modal: true,
        buttons: {
            'Delete': function () {
                // Perform the delete
                $.ajax({
                    url: "process1.php",
                    success: function () {
                        ...
                    }
                });
            },
            Cancel: function () {
                $(this).dialog('close');
            }
        }
    });
    

    【讨论】:

    • arghhhhhh...我错过了这部分...抱歉我的知识有限..非常感谢克里斯。
    【解决方案2】:

    在对话框确认 div 中放置两个按钮,“确定”和“取消”

    单击“确定”按钮后,调用您的 ajax 代码(将其重构为单独的函数)并关闭对话框。

    单击“取消”按钮后,只需关闭对话框。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-08
      • 1970-01-01
      • 2012-02-17
      • 2014-02-16
      • 2017-12-20
      • 2017-09-07
      • 1970-01-01
      • 2017-09-10
      相关资源
      最近更新 更多