【发布时间】:2014-03-19 09:09:59
【问题描述】:
我有一个 jQuery UI 对话框,里面有一个表单。我正在尝试实现一个功能,如果表单中的某个字段已被修改,我们将使用 noty 显示确认消息
现在,与 JavaScript 确认框不同,noty 不会停止脚本执行。所以,在对话框beforeClose 事件中,我是-
如果表单数据被修改,则显示通知确认,然后返回 false。 如果表单数据未被修改,则简单地返回 true。
一切正常。现在我们询问用户 -
表单中的数据已被修改。确定要关闭吗?
如果他点击no - 我们只需关闭通知并保持对话框打开。
但如果他点击yes,我们会尝试关闭对话框,这会再次触发beforeClose 事件处理程序,然后我们再次进入循环。
我尝试在调用关闭事件之前在已转换为对话框的div 上调用.off,但这似乎并没有消除点击。
这是一个简单的伪代码来解释这个问题 -
DialogCloseEvent() {
if data has been modified {
Show noty {
// IMPORTANT - This is executed after return false.
in noty user clicks NO - do not close dialog box {
close noty and done
}
in noty user clicks YES - close the dialog box {
// This calls the DialogCloseEvent again.
call the close method of the dialog box.
close noty
}
}
return false
}
no it has not been modifed {
// Closes the dialog without calling the event again
return true;
}
}
【问题讨论】:
标签: javascript jquery jquery-ui jquery-ui-dialog noty