风扇箱在关闭前允许在条件满足时关闭
fancybox beforeclose allow close when condition met
我有一个fancybox,它打开一个iFrame,用户可以在其中修改表单数据。我想这样做,如果试图关闭fancybox,就会询问用户是否希望保存所做的任何更改。我想使用带有按钮"是"、"否"answers"取消"的jQuery UI对话框来完成这项工作。此对话框是使用fancybox beforeClose回调生成和显示的。我已经能够在对话框显示时通过返回false来阻止fancybox关闭,我的问题是,我现在如何关闭fancybox?使用$.fancybox.close()只需再次触发fancyboxbeforeClose回调(循环)。
我的代码:
$.fancybox.open({
href:'/index.php?task=details_movie',
type:'iframe',
padding:10,
minHeight: '90%',
beforeClose: function() {
if ($("#dialog-confirm").length == 0) {
$("body").append('<div id="dialog-confirm" title="Save changes?"><p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Do you wish to save any changes made to the details of this movie?</p></div>');
$("#dialog-confirm").dialog({
modal:true,
buttons: [
{
text: "Yes",
click: function() {
alert("Yes"); // perform save actions
$("#dialog-confirm").remove();
}
},
{
text: "No",
click: function() {
$.fancybox.close(); // this creates the loop back to beforeClose callback
$("#dialog-confirm").remove();
}
},
{
text: "Cancel",
click: function() {
$("#dialog-confirm").remove();
return false;
}
}
]
});
$(".ui-widget-overlay").css({"z-index": 99999});
$(".ui-dialog").css({"z-index": 100000});
}
return false;
}
});
在阅读了下面的帖子后,我已经能够对我的代码进行以下更改,以获得所需的结果:
如何阻止fancyBox关闭?
- 从使用beforeClose回调更改为afterShow回调
- 取消绑定fancybox关闭按钮的点击事件
- 为fancybox关闭按钮创建了一个新的点击事件,其中包含我以前的beforeClose函数
通过这种方式,fancybox关闭按钮现在将触发jQuery UI对话框,并且根据在该对话框中选择的按钮,现在可以触发$.fancybox.close()函数,而不会像我最初的问题那样触发beforeClose循环。
我还禁用了使用escape键强制用户单击关闭按钮来关闭fancybox的功能。
我的更新代码:
$.fancybox.open({
href:'/index.php?task=details_movie',
type:'iframe',
padding:10,
minHeight: '90%',
keys : {
close : null // prevent close on escape pressed
},
afterShow: function() {
$(".fancybox-close").unbind(); // unbind events from close button
$(".fancybox-close").click(function() { // create own click event
if ($("#dialog-confirm").length == 0) {
$("body").append('<div id="dialog-confirm" title="Save changes?"><p><span class="ui-icon ui-icon-alert" style="float: left; margin: 0 7px 20px 0;"></span>Do you wish to save any changes made to the details of this movie?</p></div>');
$("#dialog-confirm").dialog({
modal:true,
buttons: [
{
text: "Yes",
click: function() {
// perform save functions
$("#dialog-confirm").remove();
$.fancybox.close();
}
},
{
text: "No",
click: function() {
$("#dialog-confirm").remove();
$.fancybox.close();
}
},
{
text: "Cancel",
click: function() {
$("#dialog-confirm").remove();
}
}
]
});
$(".ui-widget-overlay").css({"z-index": 99999});
$(".ui-dialog").css({"z-index": 100000});
}
});
}
});
相关文章:
- 当满足PHP条件时显示一个弹出窗口
- 如果满足某些条件,我如何才能创建一个只有值的对象
- 从json数组中查找满足条件的特定元素的值
- 如果满足某些条件,如何在不调用模态的情况下首先调用类
- 多次调用promise函数,直到另一个promise函数满足条件
- 在经过一段时间或满足条件后运行代码
- 在谷歌应用程序脚本中,如何在满足条件的情况下只发送一次电子邮件
- Ember.js:如果控制器中满足某些条件,则在路由器中重定向
- 禁用超链接,直到 JSP 中满足条件
- Javascript/C# - 满足语句条件时的确认对话框
- 如何在重复满足条件时调用一次辅助函数
- 如何生成一个条件提示,该提示将继续提示,直到满足条件为止
- 只有在条件满足时才加载javascript脚本-不起作用
- 风扇箱在关闭前允许在条件满足时关闭
- 而循环即使在条件满足后也不会停止
- 如果条件满足,在Angular中显示图像
- 条件满足时的Javascript重定向
- If语句条件满足,但内容未执行
- 一旦条件满足,异步调用函数
- 触发event.preventDefault ();仅当条件满足时- Jquery / javascript