SimpleModal 关闭对话框前确认
我正在使用 SimpleModal (http://www.ericmmartin.com/projects/simplemodal/ )并且我有一个显示在对话框中的表单。我想要做的是每次用户尝试关闭对话框(通过转义或单击关闭图标)时都能够出现确认,并询问他们是否真的想在不保存表单数据的情况下关闭它。我尝试了以下操作:
onClose: function (dialog) {
if (confirm('Are you sure you want to close without saving?')) {
$.modal.close();
}
}
但它只触发一次。如果您点击取消,则稍后无法再次关闭,这是有道理的。有人有建议或解决方案吗?任何帮助将不胜感激。 :)
I'm using SimpleModal (http://www.ericmmartin.com/projects/simplemodal/) and I have a form that displays in a dialog. What I want to do is be able to have a confirmation come up each time that the user tries to close the dialog (either by escape or clicking on the close icon) and asks them if they really want to close it without saving the form data. I tried the following:
onClose: function (dialog) {
if (confirm('Are you sure you want to close without saving?')) {
$.modal.close();
}
}
But it only triggers once. If you hit cancel then fails to close again later, which kind of makes sense. Anybody have a suggestion or solution? Any help would be greatly appreciated. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我为您查看了
SimpleModal
的源代码,您想要做的事情无法用他们的代码完成。这就是为什么:在调用自定义回调
onClose
之前,它会调用以下内容:这实际上表示“无论您是否喜欢,此框都将关闭”。它与您可以取消的普通回调不同。
我建议使用 jQuery UI 对话框,您应该会发现通过使用它非常容易实现该功能他们的
beforeclose
回调。您只需使用:I looked at the source of
SimpleModal
for you and what you are wanting to do can't be done with their code. This is why:Just prior to calling your custom callback
onClose
it calls this:Which effectively says "This box is going to close whether you like it or not". It is not like a normal callback which you can cancel.
I would recommend instead using the jQuery UI Dialog, which you should find super easy to implement that functionality by using their
beforeclose
callback. You would simply use:我使用 jerone 正在尝试的方式来完成此工作,但也重新绑定事件:
需要更新此插件以支持关闭事件的取消。看起来它并没有真正被视为代码中的事件。我希望它的行为就像任何其他 js 事件一样。
I got this working using sort of what jerone was trying but also rebinding the events:
This plugin needs to be updated to support the cancel of the close event. It looks like its not really being thought of as a event in the code. I would like it to behave just like any other js event.
我还查看了源代码,当执行
onclose
事件时,会启用occb
标志。您可以尝试的(我没有尝试过)是在传递给
this
变量时覆盖此occb
:希望这会有所帮助。
I've also looked at the source and when the
onclosed
event is executed aoccb
flag is enabled.What you can try (I haven't tried it) is to override this
occb
as it's passed to thethis
variable:Hope this helps.