gpt4 book ai didi

jquery - 如何阻止 fancyBox 关闭?

转载 作者:行者123 更新时间:2023-12-01 00:49:16 25 4
gpt4 key购买 nike

我正在使用fancyBox (version 2) fancyBox 中有一份联系表。我正在添加我自己的“您确定要关闭吗?”框而不是基本的confirm(),因此如果用户意外单击关闭,表单内容不会丢失。这是我正在做的事情:

$('.fancybox').fancybox({
openEffect: 'fade',
closeEffect: 'fade',
openSpeed: 'fast',
closeSpeed: 'fast',
beforeClose: function() { $('#confirm_contact_close').fadeIn(300); }
});

但是当它显示 div 时它就关闭了。除非单击"is"按钮,否则如何取消 fancyBox 的关闭?

确认div的HTML:

<div id="confirm_contact_close">
<h2 class="secondary_heading" style="font-size: 27px;">Do you really want to continue?</h1>
<p>If you continue, the entire form will be cleared.</p>
<br />
<button id="continue_contact_close">Yes</button>
<button id="cancel_contact_close">No</button>
</div>

按钮的 jQuery:

$('#confirm_contact_close').fadeIn(300);
$('#continue_contact_close').live('click', function() {
$.fancybox.close(true);
});
$('#cancel_contact_close').live('click',function() {
$('#confirm_contact_close').fadeOut(300);
});

我尝试在 beforeClose 回调中添加 return false; 但这不起作用,因为单击"is"按钮时它不会关闭那么也是如此。

提前致谢。

最佳答案

我通过解除关闭按钮的所有事件的绑定(bind)来修复此问题

$(document).ready(function() {
$('.fancybox').fancybox({
autoSize : false,
scrolling : 'auto',
beforeLoad : function() {
this.width = $(window).width()*0.95;
this.height = $(window).height()*0.95;
},

'afterShow': function() {
//override fancybox_close btn
$('.fancybox-item.fancybox-close').attr('title','Sluiten');
$('.fancybox-item.fancybox-close').unbind();
$('.fancybox-item.fancybox-close').click(function() {
var dirt_res = dirty_check('HOK');
if(is_string(dirt_res)) {
var dirt_ask = confirm(dirt_res);
if(is_string(dirt_ask)) {
} else {
parent.location.reload(true);
}
} else {
parent.location.reload(true);
}
});
}

});

});

干杯!

关于jquery - 如何阻止 fancyBox 关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8652024/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com