Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在jQuery中设置运行时回调函数_Jquery_Fancybox_Fancybox 2_Jquery Callback - Fatal编程技术网

如何在jQuery中设置运行时回调函数

如何在jQuery中设置运行时回调函数,jquery,fancybox,fancybox-2,jquery-callback,Jquery,Fancybox,Fancybox 2,Jquery Callback,有没有办法在运行时定义回调函数。 这是我需要的。 我用的是fancybox $.fancybox.open({ href : '#modal_div', minWidth:1150, minHeight:820, width:1150, height:820, autoResize:true, afterShow:function

有没有办法在运行时定义回调函数。 这是我需要的。 我用的是fancybox

$.fancybox.open({
            href : '#modal_div',
            minWidth:1150,
            minHeight:820,
            width:1150,
            height:820,
            autoResize:true,
            afterShow:function(){
                set_buttons();

            }
        });
在脚本的另一部分中,如果从服务器端收到的值为“true”,则fancybox将关闭。我所要做的是定义一个回调“afterClose”,以便只在服务器响应为true时才执行某些特定的操作,否则就不会,它应该简单地关闭

$.post("user_action.php", {
                    delete_item:item_id,
                    rel:item_type
                }, function(data){
                            if(data=="true"){
                                $.fancybox.close()
                              //do some stuff afterClose
                            }
                            else{
                            $.fancybox.close()
                            }
                }
            });

所以我所需要的就是在运行中设置回调函数

我可能没有正确理解你的问题。如果是这样,请修改您的OP,我会再试一次

实际上,您已经处于回调函数中,并且您已经正确地构造了IF测试,以查看“data”的值是否为真

因此,您可以在注释所在的位置执行所需的操作,即紧跟在
$.fancybox.close()之后指令

注意:不要忘记,在该指令之后需要一个分号,对吗