Using jquery ui dialog to confirm action for form submission

坚强是说给别人听的谎言 提交于 2019-11-28 23:46:14

You can store it in a variable like this:

var currentForm;
$("#dialog-confirm").dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            'Confirm submit': function() {
                currentForm.submit();
            },
            Cancel: function() {
                $(this).dialog('close');
            }
        }
    });
$('.allForms').submit(function(){
      currentForm = this;
      $('#dialog-confirm').dialog('open');
      return false;
});

Since you're just using this and immediately just leaving the page, no real reason to make it any more complicated than that.

Eric

Or how about

$(this.form).submit();

Based on Nick Craver his answer, you can write it this way:

$('.allForms').submit(function(){
      currentForm = this;

      $('#dialog-confirm').dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            'Confirm submit': function() {
                currentForm.submit();
            },
            Cancel: function() {
                $(this).dialog('close');
            }
        }
      });
      return false;
});
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!