我在同一页面上有几个表单,我想使用相同的代码向所有表单添加一个确认对话框。它们都有一个确认表单类,并且确认对话框的标题应该是动态生成的(这在 atm 中不起作用)。
在 html 中,我有一个在页面加载时隐藏的对话框,然后在dialog('open')
调用函数后显示。
这就是我现在所拥有的,它根本不工作,对话框加载但是一旦你按下确认,它会重复 else 子句并且不提交表单:
var deleteConfirmed = false;
$('form.confirm-form').submit(function(e) {
if ( ! deleteConfirmed)
{
e.preventDefault();
var title = $(this).find('input.action').val();
var $this = $(this);
console.log('title: ' + title);
$('#confirm-dialog').attr('title', title);
$('#confirm-dialog').dialog({
buttons : {
"Confirm" : function() {
deleteConfirmed = true;
$(this).dialog('close');
$this.submit();
},
"Cancel" : function() {
$(this).dialog('close');
}
}
});
$('#confirm-dialog').dialog('open');
}
else
{
$(this).submit();
deleteConfirmed = false;
}
});