我使用的是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.After中,关闭我需要的iframe,以获得插入值的值到父页面。我也试过这样
$(".fancybox-iframe").contents().find("#app_fee_id").val();但我无法得到结果。请给我一些解决这个问题的建议。提前感谢
发布于 2014-12-23 14:26:35
您正在尝试从iframe页面获取一个值到父页,并在父页上运行js函数。
我认为要获得从iframe到父级的值,需要在iframe页面中编写js代码。
因此,若要从成功页到父页获取隐藏字段“app_fee_id”的值(假设在加载页时填充“app_fee_id”值),请在成功页上编写以下js函数,
jQuery(document).ready(function($) {
parent.$("#parent_app_fee_id").val($("#app_fee_id").val());
});在父页中添加以下代码,
<input type='hidden' id='parent_app_fee_id' value=''>并更新“onCleanup”函数的下面一行,
feeid = jQuery('#parent_app_fee_id').val();发布于 2014-12-23 12:40:36
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();https://stackoverflow.com/questions/27620282
复制相似问题