2012-08-16 106 views
1

我想使用fancybox2创建表单。 当需要时,fancybox2表单将被显示,并且只能使用右上角的X按钮,退出键或提交,取消按钮关闭,我将在此内容中添加。 我该如何实现这一目标,以及如何禁用背景中的所有内容,以便无人能够点击它?它似乎并没有在下面的例子中为我工作:jquery fancybox2 - 如何使覆盖层上的东西不可点击

jQuery(document).ready(function(){ 
    $(".fancybox").fancybox({ 

     width:600, 
     height: 300, 
     closeBtn : true, 
     closeClick : true, 
     openEffect : 'elastic', 
     closeEffect : 'elastic', 
     scrolling : 'no', 
     autoSize : false, 
     fitToView : true 

    }); 
}); 

     <div class='fancybox' style="display: block;width:600px;height:300px;border:1px solid black;position: absolute;left:300px;top:300px;">TEST DIV</div> 
+0

http://stackoverflow.com/a/8404587/1055987 – JFK 2012-08-16 18:14:52

回答

1
$(".fancybox").fancybox({ 
    width: 600, 
    height: 300, 
    closeBtn : true, 
    closeClick : false, // prevents closing when clicking the background 
    openEffect : 'elastic', 
    closeEffect : 'elastic', 
    scrolling : 'no', 
    autoSize : false, 
    fitToView : true 
}); 

变化closeClickfalse

+0

'closeClick:false'只能在点击INSIDE fancybox时阻止关闭。点击外面的fancybox(在覆盖面具/背景上)仍然关闭fancybox。我在12月http://stackoverflow.com/a/8404587/1055987回复了这个问题 – JFK 2012-08-16 22:02:08

0

设置模式选项设置为true在facnybox脚本代码,即

$(".fancybox").fancybox({ 
    //existing stuff 
    modal : true 

}); 
+0

请注意,当使用'modal'选项时,[X]按钮不会显示,并且'escape'也不会关闭该框。关闭框的唯一方法是通过触发'$ .fancybox.close()'方法的自定义关闭按钮。 – JFK 2012-08-16 18:17:51