Using jquery ui dialog to confirm action for form submission

匿名 (未验证) 提交于 2019-12-03 02:14:01

问题:

I have multiple forms on a page, for each of them I want the user to confirm before form submission. but when the user confirms to submit, how do I let this dialog know which form the user is sumbitting? Does it take custom parameters? Thanks.

$("#dialog-confirm").dialog({         resizable: false,         height:140,         modal: true,         buttons: {             'Confirm submit': function() {                 document.______???????_____.submit();             },             Cancel: function() {                 $(this).dialog('close');             }         }     }); $('.allForms').submit(function(){       $('#dialog-confirm').dialog('open'); }); 

回答1:

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.



回答2:

Or how about

$(this.form).submit(); 


回答3:

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


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!