我正在使用fancxbox,可以将变量从fancybox子传回父级.
在子页面中有一个名为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());
}
Run Code Online (Sandbox Code Playgroud)
如果您使用的是fancybox v1.3.4,那么您将无法.val()使用onClosed回调获取value(),因为onClosed将在已删除所有fancybox内容时执行.你宁愿使用onCleanup(你仍然可以提醒x关闭fancybox之后的价值)
因此,对于Fancybox v1.3.4,请使用此API选项
"onCleanup": function(){
x = $('#fancybox-frame').contents().find('#banner_width1').val();
},
"onClosed": function(){
alert("the value of input#banner_width1 is : "+x); // optional
}
Run Code Online (Sandbox Code Playgroud)
确保您已var x;在脚本之上声明,以便可以从任何回调或任何其他功能访问它.
对于Fancybox v2.x,请使用此API选项
beforeShow : function(){
x = $('.fancybox-iframe').contents().find('#banner_width1').val();
},
afterClose: function(){
alert("the value of input#banner_width1 is : "+x); // optional
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5433 次 |
| 最近记录: |