Fancybox iframe类型在关闭时返回值 [英] Fancybox iframe type return value on close
问题描述
我正在使用fancxbox,可以将变量从fancybox子代传递回父代.
I'm using fancxbox,it is possible to pass back a variable from fancybox child to parent.
在子页面中有一个名为banner_width1
(<input name="banner_width" id="banner_width1" type="text" size="5" value="1000"/>
)
In the child page there is text field called banner_width1
(<input name="banner_width" id="banner_width1" type="text" size="5" value="1000"/>
)
'onClosed':function()
{
alert($("#banner_width1").val());
var x = $("#fancybox-frame").contentWindow.targetFunction();
alert(x.val());
}
推荐答案
如果使用的是fancybox v1.3.4,则由于onCleanup
代替(尽管在关闭fancybox之后仍可以警告x
的值)
If you are using fancybox v1.3.4 then you won't be able to get the value (.val()
) using the onClosed
callback because onClosed
will be executed when all the fancybox content has been already removed. You rather use onCleanup
instead (you can still alert the value of x
after closing fancybox though)
因此对于Fancybox v1.3.4 ,请使用此API选项
so for Fancybox v1.3.4 use this API options
"onCleanup": function(){
x = $('#fancybox-frame').contents().find('#banner_width1').val();
},
"onClosed": function(){
alert("the value of input#banner_width1 is : "+x); // optional
}
确保已在脚本顶部声明了var x;
,以使其可从任何回调或任何其他函数访问.
make sure that you have declared var x;
on top of your script to make it accessible from any callback or any other function.
对于Fancybox v2.x ,请使用此API选项
for Fancybox v2.x use this API options
beforeShow : function(){
x = $('.fancybox-iframe').contents().find('#banner_width1').val();
},
afterClose: function(){
alert("the value of input#banner_width1 is : "+x); // optional
}
这篇关于Fancybox iframe类型在关闭时返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!