我正在使用 Fancybox V1.3.4 。我有一个问题,将表单提交的值返回到父页面。我没有从当前屏幕(子框架)获取值。
添加页面
<div id ="app_fee_list">
Fee Split/ Payment Details box
<a id ="new_app_fee" href="<?php echo base_url('updateappraiserpayment/0')?>" ><i style="margin-left:15px;" class="fa fa-plus-square"></i></a>
<?php $this->load->view('andersion/appraiser/appraiserfeetemplate'); ?>
</div>
这里有像这样的fancybox代码
<script>
jQuery(document).ready(function(){
jQuery('#new_app_fee').live('click', function(){
jQuery(this).fancybox({
'width' : '60%',
'height' : '90%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe',
'onCleanup': function(){
feeid = jQuery('#appfeeform').contents().find("#app_fee_id").val();
alert(feeid);return false; // Here value returns Undefined.
// If the app_fee_id filed is in Add page it will returns.But this field is not in the ADD page. It is in the SUCCESS page.
},
'onClosed': function() {
location.reload();
}
});
}).trigger('click');
});
</script>
触发 updateappraiserpayment 页面。提交此表单后,它将重定向到成功页面。
成功页面
<form name = 'appfee1' id='appfeeform' action="<?php echo base_url('updateappraiserpayment/'.$user_id)?>" method='post'>
<div class="col-sm-12">
<section class="panel">
<div class="success">Appraiser fee information has been added successfully</div>
<input type="hidden" name='appraiser_fee_id' id ="app_fee_id" value="3">
</form>
<?php echo $appraiser_fee_id;exit; // Here i get the Inserted Id Value?>
</section>
</div>
成功消息也会显示在iframe中。关闭iframe后,我需要将插入值的值输入到父页面。我也尝试了这个
$(".fancybox-iframe").contents().find("#app_fee_id").val();
但我无法得到结果。请给我任何解决这个问题的建议。提前致谢
答案 0 :(得分:1)
您正试图从iframe页面获取一个值到父页面,并在父页面上运行js函数。
我想从iframe获取父级的值,你需要在iframe页面写一个js代码。
所以,要获得隐藏字段的价值&#39; app_fee_id&#39;从成功页面到父页面,(假设在页面加载时填充&#39; app_fee_id&#39;的值),在成功页面上编写以下js函数,
jQuery(document).ready(function($) {
parent.$("#parent_app_fee_id").val($("#app_fee_id").val());
});
在父页
中添加以下代码<input type='hidden' id='parent_app_fee_id' value=''>
并更新以下第&#39; onCleanup &#39;功能,
feeid = jQuery('#parent_app_fee_id').val();
答案 1 :(得分:0)
parent.window.document
示例:
parent.window.document.getElementById("parentPagetagId").value = 3;//set value for input parent page
parent.window.document.getElementById("fancybox-wrap").style.display = 'none';//hidden fancybox
我认为它会在这样的jQuery中(但没有检查):
$("#parentPagetagId",parent.window.document).val(3);
$("#fancybox-wrap",parent.window.document).hide();